我使用AWSIoT构建iOS应用程序。 我想通过AWSIoT将消息从iOS应用程序发布到我的raspberry pi设备。 我可以将消息从myPC发布到raspberry pi。所以,由于AWSIoT-sdk-ios认证问题,我无法前进。
我考虑两种类型。一个是认证过程,包括认证,私钥,rootCA。另一个是使用AWS-CognitoID。
如果您了解如何使用认证,私钥和rootCA编写AWSIoT认证代码,或者如何使用CognitoID,请给我讲讲。
以下代码是当前代码。 (此代码为CognitoID流程)
var iotDataManager: AWSIoTDataManager!
var iotData: AWSIoTData!
var iotManager: AWSIoTManager!
var iot: AWSIoT!
override func viewDidLoad() {
super.viewDidLoad()
//Cognito
let credentialsProvider = AWSCognitoCredentialsProvider(
regionType: .USEast1,
identityPoolId: "us-east-1:MypoolID")
let configuration = AWSServiceConfiguration(
region: .USEast1,
credentialsProvider: credentialsProvider)
AWSServiceManager.default().defaultServiceConfiguration = configuration
iotManager = AWSIoTManager.default()
iot = AWSIoT.default()
iotDataManager = AWSIoTDataManager.default()
iotData = AWSIoTData.default()
}
//publish
func publish() {
iotDataManager.publishString(mymsg, onTopic:mytopic, qoS:.messageDeliveryAttemptedAtMostOnce)
}
//publishButton
@IBAction func publishButton(sender: AnyObject) {
publish()
}