出现初始屏幕后,AWS Cognito iOS登录控制器未关闭

时间:2019-05-13 12:10:37

标签: ios swift amazon-web-services login amazon-cognito

我在我的ios应用中使用aws cognito进行用户身份验证,并且已经实现了AWSCognitoAuthenticationDelegate,当用户未登录时会返回登录屏幕。但是在呈现登录屏幕之前,我想呈现另一个屏幕,该屏幕允许用户登录或注册。 在调用getDetails()之前,我呈现了初始屏幕,它出现了,但是当登录屏幕出现并且我单击登录时,没有任何反应。 didCompleteStepWithError和getDetails没有被调用

我的登录方法如下:

    @IBAction func signInTapped(_ sender: UIButton) {



        if (usernameTextField.text != nil && passwordTextfield.text != nil)  {
            let authDetails = AWSCognitoIdentityPasswordAuthenticationDetails(username: self.usernameTextField.text!, password: passwordTextfield.text!)

            self.passwordAuthenticationCompletion?.set(result: authDetails)

            print("checking auth details")

            activityIndicator.startAnimating()



        } else {

            let alertController = UIAlertController(title: "Missing information",
                                                    message: "Please enter a valid user name and password",
                                                    preferredStyle: .alert)
            let retryAction = UIAlertAction(title: "Retry", style: .default, handler: nil)
            alertController.addAction(retryAction)




        }







    }

我正在显示启动选项屏幕,其中包含登录,viewcontroller的viewDidLoad中的注册按钮,成功登录后显示为:

self.pool = AWSCognitoIdentityUserPool(forKey: AWSCognitoUserPoolsSignInProviderKey)
        if (self.user == nil) {
            self.user = self.pool?.currentUser()
        }

        if self.user != nil && !user!.isSignedIn {

                        let vc = self.storyboard?.instantiateViewController(withIdentifier: "splashScreen") as? SplashScreenViewController

                        self.present(vc!, animated: true, completion: nil)



        }


        self.refresh()

在SignIn VC中,我的getDetails和didCompleteStepWithError方法是:

public func getDetails(_ authenticationInput: AWSCognitoIdentityPasswordAuthenticationInput, passwordAuthenticationCompletionSource: AWSTaskCompletionSource<AWSCognitoIdentityPasswordAuthenticationDetails>) {

    print("Get details called")

    self.passwordAuthenticationCompletion = passwordAuthenticationCompletionSource
    DispatchQueue.main.async {
        if (self.usernameText == nil) {
//            self.usernameText = authenticationInput.lastKnownUsername
        }
    }




    }


public func didCompleteStepWithError(_ error: Error?) {


    DispatchQueue.main.async {
        if let error = error as NSError? {

            self.activityIndicator.stopAnimating()


            let alertController = UIAlertController(title: "Incorrect Credentials", message: "Those credentials don't look right. Please try again.", preferredStyle: .alert)

            let retryAction = UIAlertAction(title: "Retry", style: .default, handler: nil)
            alertController.addAction(retryAction)

            self.present(alertController, animated: true, completion:  nil)
        } else {


            print("completed step without error")

            self.activityIndicator.stopAnimating()

            self.dismiss(animated: true, completion: {

                let vc = self.storyboard?.instantiateViewController(withIdentifier: "splashScreen") as? SplashScreenViewController

                vc?.dismiss(animated: true, completion: nil)


            })  


        }
    }








    }

我是否需要在初始屏幕中实现与登录vc中相同的协议,还是需要在signinVC中集成“注册”按钮,如aws cognito ios swift示例应用程序所示?

在不添加启动选项的情况下,屏幕注册流程运行正常

0 个答案:

没有答案