Swift AWS Cognito error: Authentication delegate not set

Swift AWS Cognito error: Authentication delegate not set

我正在 swift 开发应用程序,我使用 AWS 移动服务进行身份验证,使用 AWS Lambda 进行一些后端处理。我一切正常,有一天(离开应用程序一个月左右),它开始抛出这个错误:

 GetId failed. Error is [Error Domain=com.amazonaws.AWSCognitoIdentityProviderErrorDomain Code=-1000 "Authentication delegate not set" UserInfo {NSLocalizedDescription=Authentication delegate not set}]
 Unable to refresh. Error is [Error Domain=com.amazonaws.AWSCognitoIdentityProviderErrorDomain Code=-1000 "Authentication delegate not set"

我快要死了,因为它已经在工作了。可以改变什么?

在 appDelegate 中,我有:

func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey : Any]? = nil) -> Bool {

        // Uncomment to turn on logging, look for "Welcome to AWS!" to confirm success
        AWSDDLog.add(AWSDDTTYLogger.sharedInstance)
        AWSDDLog.sharedInstance.logLevel = .error

        // Instantiate AWSMobileClient to get AWS user credentials
        return AWSMobileClient.sharedInstance().interceptApplication(application, didFinishLaunchingWithOptions:launchOptions)
    }

它实际上是在我进行任何调用之前抛出错误,所以我认为上面的行可能触发了问题?

要登录,我在主 viewController 中执行以下操作:

override func viewDidLoad() {
        super.viewDidLoad()

        if !AWSSignInManager.sharedInstance().isLoggedIn {
            presentAuthUIViewController()
        }
        else{
            getCredentials()
        } 
        ...
        }

func presentAuthUIViewController() {
        let config = AWSAuthUIConfiguration()
        config.enableUserPoolsUI = true
        config.backgroundColor = UIColor.white
        config.logoImage = #imageLiteral(resourceName: "logoQ")
        config.isBackgroundColorFullScreen = true
        config.canCancel = true

        AWSAuthUIViewController.presentViewController(
            with: self.navigationController!,
            configuration: config, completionHandler: { (provider: 
            AWSSignInProvider, error: Error?) in
                if error == nil {
                    self.getCredentials()
                } else {
                    // end user faced error while loggin in, take any required action here.
                }
        })
    }

    func getCredentials() {
        let serviceConfiguration = AWSServiceConfiguration(region: .USEast1, credentialsProvider: nil)
        let userPoolConfiguration = AWSCognitoIdentityUserPoolConfiguration(clientId: "id",
                                                                            clientSecret: "secret",
                                                                            poolId: "id")
        AWSCognitoIdentityUserPool.register(with: serviceConfiguration, userPoolConfiguration: userPoolConfiguration, forKey: "key")
        let pool = AWSCognitoIdentityUserPool(forKey: "key")
        if let username = pool.currentUser()?.username {
            userName = username
        }

它登录了,我检索了用户名。

有什么建议吗?我遵循了其他帖子中的一些说明,但它们没有用,而且最让我感到不安的是它起作用了!

提前致谢

因此,不能 100% 确定发生了什么,但据我了解,用户池中用户的凭据存在问题。我重置了密码,一切又开始正常工作了!

如果有人需要更多详细信息,请询问,如果有人更了解这一点,请告诉我..

我认为这意味着您的刷新令牌已过期。