简体   繁体   中英

How do I switch to login screen with the startPasswordAuthentication delegate in iOS/Swift for Cognito User Pools based login?

I've translated the Obj-C code from CognitoYourUserPoolsSample to Swift with aws-ios-sdk-2.4.5. I've set up a user pool, an app and included the correct ids in the project. However, when I run the app, the startPasswordAuthentication delegate method never gets called and I'm unable to figure out why. I'm including the code in the AppDelegate.application method below. If anyone can give me some pointers on how to fix/debug this it will be very helpful.

class AppDelegate: UIResponder, UIApplicationDelegate, AWSCognitoIdentityInteractiveAuthenticationDelegate {

func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
    AWSLogger.defaultLogger().logLevel = AWSLogLevel.Verbose
    let sc = AWSServiceConfiguration(region: .USEast1, credentialsProvider: nil)
    let upc = AWSCognitoIdentityUserPoolConfiguration(clientId: clientId, clientSecret: clientSecret, poolId: userPoolId)
    AWSCognitoIdentityUserPool.registerCognitoIdentityUserPoolWithConfiguration(sc, userPoolConfiguration: upc, forKey: "UserPool")
    let pool = AWSCognitoIdentityUserPool(forKey: "UserPool")
    self.storyboard = UIStoryboard(name: "Main", bundle: nil)
    pool.delegate = self
    return true
}

func startPasswordAuthentication() -> AWSCognitoIdentityPasswordAuthentication {
    print("show login ui")
    let mainStoryboard: UIStoryboard = UIStoryboard(name: "Main", bundle: nil)
    let loginViewController = mainStoryboard.instantiateViewControllerWithIdentifier("LoginViewController") as? LoginViewController
    dispatch_async(dispatch_get_main_queue(), {
        self.window?.rootViewController = loginViewController
    })
    return loginViewController!
}
}

I'm able to run the Obj-C sample project locally and the startPasswordAuthentication delete method is being called!

I don't know if I am right, but I think you forget to migrate your pool with identity pool .

let sc = AWSServiceConfiguration(region: .USEast1,credentialsProvider: nil)

AWSServiceManager.defaultServiceManager().defaultServiceConfiguration = sc

let upc = AWSCognitoIdentityUserPoolConfiguration(clientId: "CLIENT_ID", clientSecret: "CLIENT_SECRET", poolId:"USER_POOL_ID")

AWSCognitoIdentityUserPool.registerCognitoIdentityUserPoolWithConfiguration(sc, userPoolConfiguration: upc, forKey: "UserPool")

let pool = AWSCognitoIdentityUserPool(forKey:"UserPool")

***credentialsProvider = AWSCognitoCredentialsProvider(regionType: .USEast1, identityPoolId: "COGNITO_IDENTITY_POOL_ID, identityProviderManager:pool)***

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM