Q:

AWS Cognito iOS trying to goto splash page instead of login page if there is no user logged in

I'm currently trying to integrate Amazon Cognito with my iOS app. I have the app delegate conform to the AWSCognitoIdentityInteractiveAuthenticationDelegate protocol and I understand when the user is not logged in, the startPasswordAuthentication() function is called and I have to return the login view controller. However, I want the user to be directed to a splash page rather than the login page if the user is not logged in. The splash screen has an option to login or to register. I tried just presenting the splash screen in startPasswordAuthentication() method and returning the loginViewController, but then the Amazon Cognito login functionality does not work. Is there any workarounds?

A:

If you call getDetails or getSession on the cognito user, it's going to trigger the startPasswordAuthentication code flow, which as you've discovered isn't allowing you to return anything that doesn't implement AWSCognitoIdentityPasswordAuthentication.  You'll want to handle presenting the splash screen before you call getDetails on the user.
The AWSCognitoIdentityUser object has a property to test whether the user is signed in or not.
let pool = AWSCognitoIdentityUserPool(forKey: AWSCognitoUserPoolsSignInProviderKey)
let user = pool?.currentUser()
if user != nil && !user!.isSignedIn {
    // present your splash screen
}

You could try this out in the User Pools Sample inside the refresh() method of the UserDetailTableViewController for example.

