如何使用 PIN 码使用 Sony Bravia TV IP Control 进行身份验证?

How to authenticate with Sony Bravia TV IP Control with pin code?

提问人:Trần Nghĩa 提问时间:11/13/2023 最后编辑:HangarRashTrần Nghĩa 更新时间:11/13/2023 访问量:31

问:

通常,要对 Sony Bravia TV 进行身份验证,我使用预共享密钥并且可以正常工作。但是我看到有些应用程序可以使用PIN码进行身份验证,并且PIN码显示在电视屏幕上。如何为我的 iOS 应用程序执行此操作?当我请求电视时,PIN码只显示了大约1秒钟,然后它立即消失了。我也使用插座与电视通信,但我不知道如何验证。这是我的代码:

let ipAddress = "192.168.1.94"
let port: Int32 = 80
let path = "/sony/accessControl"
let requestBody: String = """
{
"id": 1001,
"method": "actRegister",
"params": [
{
"clientid": "iRule:1",
"nickname": "Tran Nghia Pro"
},
[
{
"clientid": "iRule:1",
"value": "no",
"nickname": "Tran Nghia Pro",
"function": "WOL"
}
]
],
"version": "1.0"
}
""" 
let request = """
POST \(path) HTTP/1.1\r
Host: \(ipAddress)\r
Content-Type: application/json\r
Content-Length: \(requestBody.count)\r
\r
\(requestBody)
"""
let client = TCPClient(address: ipAddress, port: port)
switch client.connect(timeout: 5) {
case .success:
// Send the POST request
switch client.send(string: request) {
case .success:
// Read the response
if let data = client.read(1024) {
if let responseString = String(bytes: data, encoding: .utf8) {
print("Response: \(responseString)")
} else {
print("Invalid response data")
}
} else {
print("No data received")
}
// Close the connection
client.close()
case .failure(let error):
print("Error sending request: \(error.localizedDescription)")
}
case .failure(let error):
print("Error connecting to server: \(error.localizedDescription)")
}
iOS Swift socket.io Sony 是后请求

评论

1赞 HangarRash 11/13/2023
请正确缩进您的代码,使其更具可读性。

答: 暂无答案