值在「用戶名」不能滿足約束:成員的長度必須大於或等於1;在「用戶名」值不能滿足約束:成員必須滿足正則表達式模式:[\ 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和@IBAction中的「確認」方法和您自己的SEGUE;插入後,您檢查,看看是否碼值是空的,之前「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語句...