0

我需要组中的事物列表或来自 AWS 的事物列表,我试图从AWSIoT 参考中找到解决方案所以我使用下面的代码来获取它。以前我使用来自后端服务的普通 API 调用来获取它,但我需要完全使用 AWS。

   func initializeAWS() {

       let credentialsProvider = AWSCognitoCredentialsProvider(regionType:AWS_REGION,
                                                               identityPoolId:IDENTITY_POOL_ID)
       initializeControlPlane(credentialsProvider: credentialsProvider)

   }

   func initializeControlPlane(credentialsProvider: AWSCredentialsProvider) {

       let controlPlaneServiceConfiguration = AWSServiceConfiguration(region:AWS_REGION, credentialsProvider:credentialsProvider)

       AWSServiceManager.default().defaultServiceConfiguration = controlPlaneServiceConfiguration
       iot = AWSIoT.default()

       let request = AWSIoTListThingsInThingGroupRequest()
       request?.thingGroupName = "XXXGroupName"
       let output = iot.listThings(inThingGroup: request!)
       print("output is \(output.result)")
       print("error is \(output.error)")

   }

我在这里使用AWSIoT& AWSIoTListThingsInThingGroupRequestobject 来获取事物列表,我可能知道这是正确的获取方式吗?如果是我output,并且error两个对象都为零。

我试图从 Github 找到 AWS IOT 示例的解决方案,但没有得到任何相关答案。或者有什么东西iotDataManager可以列出东西吗?请问你能帮我吗?有关更多信息,我在 AWS Github Fetching list of things group 中提出了问题

4

1 回答 1

0

我已经检查了日志级别的输出,所有配置也是正确的,唯一我不知道的是如何获得事物的响应,获得事物的方式如下。

let credentialsProvider = AWSCognitoCredentialsProvider(regionType:AWS_REGION,
                                                        identityPoolId:IDENTITY_POOL_ID)

let controlPlaneServiceConfiguration = AWSServiceConfiguration(region:AWS_REGION, credentialsProvider:credentialsProvider)

AWSServiceManager.default().defaultServiceConfiguration = controlPlaneServiceConfiguration
iot = AWSIoT.default()

let request = AWSIoTListThingsInThingGroupRequest()
request?.thingGroupName = "XXXGroupName"
let output = iot.listThings(inThingGroup: request!)

output.continueOnSuccessWith { (response) -> Any? in

    if let result = response.result, let things = result.things {
        self.awsDevices = things
        completionHandler(true)
    }
    return self.awsDevices

}
于 2020-04-22T05:16:53.557 回答