iOS 上的 Mobile Hub Cognito

Mobile Hub Cognito on iOS

我一直在开发一个使用 AWS Mobile Hub 作为后端的 iOS 应用程序,但我似乎无法弄清楚如何为用户实施自定义身份验证 UI登录功能。更好的是,我找不到任何文档至少可以提示我应该如何去做。我发现的唯一一点资源是 AWS 提供的 Auth UI 功能,这在我的情况下并不理想。 (我应该提一下,我对 swift 上的 AWS 开发有点陌生)

我的想法是,当您在 Mobile Hub 上启动新项目时,我可以使用提供给您的 awsconfiguration.json,然后将其集成到 UIViewController class 在不使用 AuthUI 库的情况下用于身份验证。

这是我试过的方法:

@IBOutlet weak var emailField: UITextField!
@IBOutlet weak var passwordField: UITextField!

var passwordAuthenticationCompletion: AWSTaskCompletionSource<AWSCognitoIdentityPasswordAuthenticationDetails>!

func getDetails(_ authenticationInput: AWSCognitoIdentityPasswordAuthenticationInput, passwordAuthenticationCompletionSource: AWSTaskCompletionSource<AWSCognitoIdentityPasswordAuthenticationDetails>) {
    passwordAuthenticationCompletion = passwordAuthenticationCompletionSource
}

@IBAction func logInTapped(_ sender: Any) {
    var emailText = emailField.text!
    var passwordText = passwordField.text!

    passwordAuthenticationCompletion.set(result: AWSCognitoIdentityPasswordAuthenticationDetails.init(username: emailText, password: passwordText))
}

func didCompleteStepWithError(_ error: Error?) {
    if error != nil {
        let alertController = UIAlertController(title: error?.localizedDescription, message: "error", preferredStyle: UIAlertControllerStyle.alert)
        alertController.addAction(UIAlertAction(title: "Dismiss", style: UIAlertActionStyle.default, handler: nil))

        self.present(alertController, animated: true, completion: nil)
    } else {
        print("logged in")
    }
}

调用 passwordAuthenticationCompletion.set() 时返回 nil。 有人可以告诉我我做错了什么,或者可以指出正确的方向吗?

谢谢。

找到了。
访问附加到移动中心的默认认知用户池的方法是导入 AWSUserPoolsSignIn 库,并使用 AWSCognitoUserPoolsSignInProvider.sharedInstance().