注册期间无法获取用户的UUID(子):Amazon Cognito

时间:2017-12-01 03:38:36

标签: swift amazon-web-services aws-cognito

我正在尝试使用AWS Cognito注册用户。

我从these docs中显示的注册方法了解到,注册方法的回调返回err and data,数据参数应该包含userub或UUID(例如UUID:671fff45-77aa-4867- b11f-47c8bfa246a9)。 我无法调用方法(data.UserSub)来检索它,swift抛出错误

  

类型的价值' AWSCognitoIdentityUserPoolSignUpResponse'没有会员   ' USERSUB'

请参阅SignUp()中的第3个print语句,了解完整的上下文。

class Login: UIViewController{
    var pool: AWSCognitoIdentityUserPool?

     override func viewDidLoad() {
        super.viewDidLoad()

       let AWSCognitoUserPoolsSignInProviderKey = "UserPool"
        self.pool = AWSCognitoIdentityUserPool.init(forKey: AWSCognitoUserPoolsSignInProviderKey)

       signUp()

    }

}


func signUp(){

    let userNameValue = "+" + UserData.mobileNumberWithCountryCode
        print("userNameValue: \(userNameValue)")
    let passwordValue = "somePassword" 

        var attributes = [AWSCognitoIdentityUserAttributeType]()

    self.pool?.signUp(userNameValue, password: passwordValue, userAttributes: attributes, validationData: nil).continueWith {[weak self] (task) -> Any? in

    guard let strongSelf = self else {
                    print("Returninig nil on Strong Self")
                    return nil
                }

                DispatchQueue.main.async(execute: {
                    if let error = task.error as? NSError {

                        print("There is an error")

                    }else if let result = task.result  {
                        // The above line prints userName
                        print("userName after sub:\(result.user.username)") 

                       //the below line throws a swift error: Value of type 'AWSCognitoIdentityUserPoolSignUpResponse' has no member 'UserSub'
                       print("userName after sub:\(result.UserSub)")

               }

}
}

1 个答案:

答案 0 :(得分:0)

您使用的是哪个版本的SDK?如果您使用的是最新版本,可能只是外壳错误,应该是.userSub 见:http://docs.aws.amazon.com/AWSiOSSDK/latest/Classes/AWSCognitoIdentityProviderSignUpResponse.html#//api/name/userSub