2017-10-20 1 views
0

AWSでユーザーアカウントを作成すると、そのアプリケーションを終了してから、電子メールに送信されたコードを使用して確認します/ SMSの場合、入力したユーザー名は1文字以上でなければならず、何らかのパターンに従わなければなりません。これはamazonが同様に投稿したサンプルコードのバグです。トピックに関する文献がなく、非常に不満な問題だったので、私の解決策を投稿したいので、私はここに投稿しています。アカウント作成後にAmazon Web Servicesで未確認のユーザーを確認する(アプリ内)

はここでエラーです:「ユーザー名」での

値は、制約を満たすために失敗しました。メンバーは、1以上の長さを持っている必要があります。 'username'の値が制約を満たさない:メンバは正規表現のパターンを満たさなければならない:[\ p {L} \ p {M} \ p {S} \ p {N} \ p {P}] + ";

答えて

0

'username'の値が制約を満たさない:メンバーの長さが1以上でなければならず、 'username'の値が制約を満たさない:メンバーが正規表現パターン[\ p {L} \ p {M} \ p {S} \ p {N} \ p {P}] + ";

最初にアカウントを作成すると、ユーザーストーリーボードの確認が行われ、ユーザー名とコードを入力する必要があります。ただし、未確認のアカウントで技術的にログインしているため、ユーザー名はすでに入力されています。ただし、未確認のアカウントでログインできる唯一の時間です(他の回避策が見つからない限り)。したがって、ユーザコントローラの確認に戻る場合、入力されたユーザ名ではなくログインしたユーザのユーザ名をコードに使用するため、単にユーザ名を入力することはできません。この問題を解決してユーザー名とコードを入力し、アカウントを確認するだけです。

これはので、ここでスタック内の私の最初の投稿です私の最高の答えです:メソッドで

...

override func viewDidLoad() { 

変更...

self.username.text = self.user!.username 

に....

if self.user?.username == "" || self.user == nil { 
    print("user is nil") 
} else { 
    self.username.text = self.user!.username 
} 

....あなたのpoolIDとあなたの "Confirm"メソッドとあなた自身のSEGUEのための@IBActionにあります。あなたは、コードの値が空の前であるかどうかを確認後、「self.user .confirmSignUp?」方法をそれを挿入...

if self.user?.username == "" || self.user == nil { 
// change the poolid to yours 
    let pool = AWSCognitoIdentityUserPool(fenter code hereorKey: userPoolID) 
// change the "username" title to whatever corresponds to the text field identifier you are using 
    let user = pool.getUser((self.username?.text)!) 

    user.confirmSignUp(self.code.text!, forceAliasCreation: true).continueWith {[weak self] (task: AWSTask) -> AnyObject? in 
    guard let strongSelf = self else { return nil } 
    DispatchQueue.main.async(execute: { 
     if let error = task.error as? NSError { 
      let alertController = UIAlertController(title: error.userInfo["__type"] as? String, message: error.userInfo["message"] as? String, preferredStyle: .alert) 
      let okAction = UIAlertAction(title: "Ok", style: .default, handler: nil) 
      alertController.addAction(okAction) 
      strongSelf.present(alertController, animated: true, completion: nil) 
     } else { 
      // Change the segue identifier to yours 
      strongSelf.performSegue(withIdentifier: "confirmedUserSegue", sender:sender) 
     } 
    }) 
return nil 
} 
} 

・ホープこのことができます!

同じことを行う、再送コードを修正するには:

if self.user?.username == "" || self.user == nil { 
      let pool = AWSCognitoIdentityUserPool(forKey: userPoolID) 
      let user = pool.getUser((self.username?.text)!) 

      user.resendConfirmationCode().continueWith {[weak self] (task: AWSTask) -> AnyObject? in 
       guard let _ = self else { return nil } 
       DispatchQueue.main.async(execute: { 
        if let error = task.error as? NSError { 
         let alertController = UIAlertController(title: error.userInfo["__type"] as? String, 
                   message: error.userInfo["message"] as? String, 
                   preferredStyle: .alert) 
         let okAction = UIAlertAction(title: "Ok", style: .default, handler: nil) 
         alertController.addAction(okAction) 

         self?.present(alertController, animated: true, completion: nil) 
        } else if let result = task.result { 
         let alertController = UIAlertController(title: "Code Resent", 
                   message: "Code resent to \(result.codeDeliveryDetails?.destination!)", 
          preferredStyle: .alert) 
         let okAction = UIAlertAction(title: "Ok", style: .default, handler: nil) 
         alertController.addAction(okAction) 
         self?.present(alertController, animated: true, completion: nil) 
        } 
       }) 
       return nil 
      } 

     } else 

を... else文でアマゾン例からのコードの残りの部分...

関連する問題