我需要组中的事物列表或来自AWS的事物列表,我试图从AWSIoT Reference中找到解决方案,所以我使用下面的代码来获取它。以前,我曾经使用后端服务中的常规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
和AWSIoTListThingsInThingGroupRequest
对象来获取我可能知道这是正确的获取方法的列表?如果是的话,我是output
和error
两个对象都为零。
我试图从Github中找到AWS IOT示例的解决方案,但没有得到任何相关的答案。或者iotDataManager
中是否有任何东西可以列出清单?请你能帮我吗?有关更多信息,我对AWS Github Fetching list of things in things group
答案 0 :(得分: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
}