【问题标题】:Fetching list of things in things group or things from AWS IoT从 AWS IoT 获取事物组或事物中的事物列表
【发布时间】:2020-08-03 20:06:24
【问题描述】:

我需要组中的事物列表或来自 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)")

   }

我在这里使用了AWSIoTAWSIoTListThingsInThingGroupRequest 对象来获取事物列表,我可以知道这是正确的获取方式吗?如果是我outputerror 两个对象都为零。

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

上提出了问题

【问题讨论】:

    标签: ios swift amazon-web-services aws-iot aws-sdk-ios


    【解决方案1】:

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

    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
    
    }
    

    【讨论】:

      猜你喜欢
      • 2016-10-01
      • 1970-01-01
      • 1970-01-01
      • 2020-08-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-08-02
      • 2019-01-27
      相关资源
      最近更新 更多