我正在尝试使用 IAM 用户凭证登录 AWS iOT。 但是我不断收到错误“连接错误”,在控制台中它显示为“CP Conn 0x2819e8a80 SSLHandshake 失败(-9807)”。我检查了不同的 wifi 连接,但仍然遇到相同的错误。
在这里我分享我的代码以获得更多的清晰度,
let credentialsProvider = AWSStaticCredentialsProvider(accessKey: myAccessKey, secretKey: mySecretKey)
let configuration = AWSServiceConfiguration(region: AWSRegionType.USEast1, credentialsProvider: credentialsProvider)
AWSIoTDataManager.register(with: configuration!, forKey: "iOTManager")
iotDataManager = AWSIoTDataManager(forKey: "iOTManager")
#if DEMONSTRATE_LAST_WILL_AND_TESTAMENT
let lwtTopic: NSString = Constants.lwtTopic
let lwtMessage: NSString = Constants.lwtMessage
self.iotDataManager.mqttConfiguration.lastWillAndTestament.topic = lwtTopic as String
self.iotDataManager.mqttConfiguration.lastWillAndTestament.message = lwtMessage as String
self.iotDataManager.mqttConfiguration.lastWillAndTestament.qos = .AtMostOnce
#endif
self.iotDataManager.connectUsingWebSocket( withClientId: UUID().uuidString, cleanSession:true, statusCallback: mqttEventCallback)
}
func mqttEventCallback( _ status: AWSIoTMQTTStatus ) {
DispatchQueue.main.async {
print(status.rawValue)
switch(status)
{
case .connecting:
print("Connecting..!")
case .connected:
print("Connected..!")
case .disconnected:
print("Disconnected..!")
case .connectionRefused:
print("connectionRefused..!")
case .connectionError:
print("connectionError..!")
case .protocolError:
print("protocolError..!")
default:
print("unknowState" + String(status.rawValue))
}
}
当我在 iPad mini 中运行相同的代码时,我能够成功登录到 AWS iOT,但它不能在 iPhone(7、7Plus、8Plus)中登录。我想知道,为什么会这样。我没有在代码中弄错什么。请帮我解决这个问题。
最佳答案
经过一番研究,我发现了这两件事
1) 使用带有“-ats”或“.ats”的新端点时 SSL 握手失败 here
2) 它在更高版本 (IOS 12.1.1) 中出现问题,因此请检查您的设备版本。
请引用这个Doc还有
关于ios - 使用 IAM 用户凭证 iOS 的 AWS iOT 登录问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55042958/