首页 > 解决方案 > Swift - AWSTaskCompletionSource 示例

问题描述

根据这个链接,我可以使用异步AWSTaskCompletionSource获取identitytoken,但我似乎找不到任何关于它的例子。

你能告诉我一些我可以开始设置identityIdtoken异步的例子吗?

提前致谢

标签: swiftamazon-web-servicesasynchronousaws-sdk

解决方案


这是一个迟到的答案,但也许有人可能仍在寻找如何使用它,这是一个示例

//inside the token function or any other function create a completion object
let completionSource = AWSTaskCompletionSource<NSString>()
        
        //then call your backend to fetch the token and identityId
        self.idCancellable = GetAWSDevOpenId().call().sink(receiveCompletion: { _ in}) { [weak self , completionSource] (credentials : [String]?) in
            if let cred = credentials , let self = self, cred.count > 1 {
                print(">>>>>>>>>>>>> Id successfully fetched: \(cred)")

                //then update the token and identityId
                self.identityId = cred.first
                completionSource.set(result: cred[1] as NSString)
            } else {
                print(">>>>>> something went wrong")
                completionSource.set(error: NSError())
            }
        }
        
        //return the task
        return completionSource.task



推荐阅读