2016-10-05 16 views
0

でブロック内のコードを実行しません、私はAWS Cognitoで動作するように始めていると、ユーザー登録時に捕まってしまった...AWS Pool.SignupがOKスウィフト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と通信しています。私が「Sign In Optional」でそれを実行すると、認証されていなくても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を使用し、 ""は使用しないでください。クライアントの秘密を使うことを強くお勧めします。