swift - Swift - AWSTaskCompletionSource 示例
问题描述
根据这个链接,我可以使用异步AWSTaskCompletionSource
获取identity
和token
,但我似乎找不到任何关于它的例子。
你能告诉我一些我可以开始设置identityId
和token
异步的例子吗?
提前致谢
解决方案
这是一个迟到的答案,但也许有人可能仍在寻找如何使用它,这是一个示例
//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
推荐阅读
- javascript - 使用函数添加到现有的 xpath?
- javascript - 如何使用 JavaScript 返回查询 CSS 元素
- javascript - 你如何创建一个空闲会话计时器,用 react redux 将用户注销?
- reactjs - 从 PrimeReact 更改圆环图的标签位置
- visual-studio - 在 Windows 上为 VisualC++ 链接 gRPC
- database-design - 如何为用户可编辑字段设计数据库模型?
- java - 给定案例的正则表达式是什么?
- c - 如何在嵌入式 C while 循环中继续接收定时中断?
- python - 使用 Django 安装 Google Analytics 跟踪代码
- list - Dart 的 List 的“some”方法叫什么?检查至少一个元素是否通过测试的方法