2016-10-05 37 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,請勿使用「」。我強烈建議你使用客戶端密碼。