ios - 使用 IAM 用户凭证 iOS 的 AWS iOT 登录问题

标签 ios swift xcode amazon-web-services aws-iot

我正在尝试使用 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/

相关文章:

ios - Xcode 8 消息模板应用程序 : Error on iOS Simulator

ios - 密码的 XML 解析,无需在数据库中存储/缓存

swift - 如何修复 'Line Length Violation: Line should be 120 characters or less' - SwiftLint

swift - 在Xcode中,如何切换分支、 merge 变更、选择 merge 哪些变更?

ios - 其他链接器标志 -ObjC 导致 "Symbol not found"错误

ios - iPad 应用程序在安装到设备时卡住

ios - Storyboard只加载一次

ios - 消耗品应用内购买已购买

iphone - 仪器,目标运行失败 : Remote exception encountered : 'Failed to get task for pid'

ios - urlNode.objectForKeyedSubscript ("href")作为?字符串 - Swift 2.3/Swift 3 错误