0

我目前正在尝试将 Amazon Cognito 与我的 iOS 应用程序集成。我让应用程序委托符合 AWSCognitoIdentityInteractiveAuthenticationDelegate 协议,并且我了解当用户未登录时,将调用 startPasswordAuthentication() 函数并且我必须返回登录视图控制器。但是,如果用户未登录,我希望将用户定向到启动页面而不是登录页面。启动屏幕可以选择登录或注册。我尝试在 startPasswordAuthentication() 方法中显示初始屏幕并返回 loginViewController,但随后 Amazon Cognito 登录功能不起作用。有什么解决方法吗?

4

1 回答 1

1

如果您在 cognito 用户上调用 getDetails 或 getSession,它将触发 startPasswordAuthentication 代码流,正如您所发现的那样,它不允许您返回任何未实现 AWSCognitoIdentityPasswordAuthentication 的内容。在对用户调用 getDetails 之前,您需要处理显示初始屏幕。

AWSCognitoIdentityUser 对象有一个属性来测试用户是否登录。

let pool = AWSCognitoIdentityUserPool(forKey: AWSCognitoUserPoolsSignInProviderKey)
let user = pool?.currentUser()
if let user = user, !user.isSignedIn {
    // present your splash screen
}

例如,您可以在UserDetailTableViewController的 refresh() 方法中的用户池示例中尝试这一点。

于 2018-04-08T06:36:43.693 回答