我正在尝试使用 Amazon Cognito 和 Twitter Digits 对用户进行身份验证。当我创建用户时,会创建一个与 Digits 登录没有任何连接的未经身份验证的用户。
这是我的代码:
override func viewDidLoad() {
super.viewDidLoad()
let credentialsProvider = AWSCognitoCredentialsProvider(regionType:.USEast1, identityPoolId:"us-east-1:1b21eda6-56e8-4094-a7af-XXXXXXXXXXXX")
let configuration = AWSServiceConfiguration(region: .USEast1, credentialsProvider: credentialsProvider)
AWSServiceManager.defaultServiceManager().defaultServiceConfiguration = configuration
let authButton = DGTAuthenticateButton(authenticationCompletion: { (session: DGTSession?, error: NSError?) in
if (session != nil) {
let value = (session!.authToken)! + ";" + (session!.authTokenSecret)!
credentialsProvider.logins = ["www.digits.com" : value]
credentialsProvider.getIdentityId().continueWithBlock({ (task) -> AnyObject? in
print(task.result)
print(task.error)
return nil
})
self.saveNumber((session?.phoneNumber)!)
} else {
print("Authentication error: \(error!.localizedDescription)")
}
})
authButton.center = self.view.center
self.view.addSubview(authButton)
}
和代码saveNumber
:
func saveNumber(number : String) {
let syncClient = AWSCognito.defaultCognito()
let dataset = syncClient.openOrCreateDataset("userInfo")
dataset.setString(number, forKey: "phoneNumber")
dataset.synchronize().continueWithBlock { (task) -> AnyObject? in
if task.error != nil {
print("Uh Oh")
print(task.error?.localizedDescription)
}else{
print("Yay!")
}
return nil
}
}
有任何想法吗?谢谢!