2016-10-05 40 views
0

好吧,我开始与AWS Cognito工作,被困在用户注册......AWS Pool.Signup不会在雨燕的内部块执行代码3

这是我的问题是发生了什么:

func register(userNameChosen:String, attributes:[AWSCognitoIdentityUserAttributeType]) { 
    let task = self.pool.signUp(userNameChosen, password: senhaTextField.text!, userAttributes: attributes, validationData: nil) 

    task.continue(with: AWSExecutor.default(), with: { (task) -> Any? in 

      if task.error != nil { //error occur 
       let alert:UIAlertController = UIAlertController(title: "Error", message: task.error?.localizedDescription, preferredStyle: UIAlertControllerStyle.alert) 
       alert.addAction(UIAlertAction(title: "Click", style: UIAlertActionStyle.default, handler: nil)) 
       self.present(alert, animated: true, completion: nil) 



      } else { //no error 
       print("no error") 
       let response:AWSCognitoIdentityUserPoolSignUpResponse = task.result! as AWSCognitoIdentityUserPoolSignUpResponse 
       self.user = response.user 

       if response.userConfirmed as! Int != AWSCognitoIdentityUserStatus.confirmed.rawValue { //user not confirmed via email 
        //setup para mandar atraves de Segue 
        self.sentTo = response.codeDeliveryDetails?.destination 
        self.performSegue(withIdentifier: "confirmSignUp", sender: self) 

       } else { 
        print("User already confirmed?") 
        self.navigationController?.popToRootViewController(animated: true) //back to login  
       } 

      } 

     return nil 
    }).waitUntilFinished() 
} 

问题是,下面

task.continue(with: AWSExecutor.default(), with: { (task) -> Any? in 

代码将无法执行...... 该应用程序已与AWS沟通好。当我使用“登录可选”运行它时,即使未经身份验证,它也会获得AWS令牌。但是,当我设置登录到移动需要集线器 - Cognito,我收到以下消息(这我不认为是问题的一部分,因为之前你注册,你显然未认证):

[26851:2009541] AWSiOSSDK v2.4.9 [Error] AWSIdentityProvider.m line:304 | __52-[AWSCognitoCredentialsProviderHelper getIdentityId]_block_invoke255 | GetId failed. Error is [Error Domain=com.amazonaws.AWSCognitoIdentityErrorDomain Code=8 "(null)" UserInfo={__type=NotAuthorizedException, message=Unauthenticated access is not supported for this identity pool.}] 

或者

[26851:2009539] [] -[NWConcrete_tcp_connection dealloc] 1 
2016-10-04 21:02:33.759918 App Aws[26851:2009462] subsystem: com.apple.UIKit, category: Touch, enable_level: 0, persist_level: 0, default_ttl: 1, info_ttl: 0, debug_ttl: 0, generate_symptoms: 0, enable_oversize: 1, privacy_setting: 2, enable_private_data: 0 

回答

0

我想通了。问题是,如果没有得到AWSTask的“响应”,它将不会进入该块内,也不会抛出错误。

我配置我的凭据不知何故错误,所以它不能附加到我的UserPool。

这里是我使用的代码,如果有人使用Swift 3.0。

let serviceConfiguration:AWSServiceConfiguration = AWSServiceConfiguration.init(region: .usEast1, credentialsProvider: nil) 

    let configuration:AWSCognitoIdentityUserPoolConfiguration = AWSCognitoIdentityUserPoolConfiguration(clientId: "PUT_YOUR_CLIENT_ID_HERE", clientSecret: PUT_YOUR_CLIENT_SECRET_HERE, poolId: "PUT_YOUR_POOL_ID_HERE") 
    AWSCognitoIdentityUserPool.register(with: serviceConfiguration, userPoolConfiguration: configuration, forKey: "UserPool") 

    AWSServiceManager.default().defaultServiceConfiguration = serviceConfiguration 

如果您的客户端密码为空,请使用nil,请勿使用“”。我强烈建议你使用客户端密码。