How to handling login redirects back to app from multiple social login accounts swift?

Viewed 941

I am making an app that allows user to login from different platforms such as google, Facebook , twitter etc. In the App delegate we have to implement a function application:openURL:options: for each of the platforms. Currently my function looks like this.

func application(_ app: UIApplication, open url: URL, options: [UIApplicationOpenURLOptionsKey : Any] = [:]) -> Bool {

    // Todo handle based on the the arguments and return the bool value to be checked on iPHONE with facebook, google and twitter app
    let handled = FBSDKApplicationDelegate.sharedInstance().application(app, open: url, sourceApplication: options[UIApplicationOpenURLOptionsKey.sourceApplication] as! String!, annotation: options[UIApplicationOpenURLOptionsKey.annotation])

    GIDSignIn.sharedInstance().handle(url, sourceApplication:options[UIApplicationOpenURLOptionsKey.sourceApplication] as? String, annotation: [:])

    Twitter.sharedInstance().application(app, open: url, options: options)

    return handled
}

As seen above I am returning handled that is the Facebook's redirect handle result. Google and twitter returns a bool value too. What is the safest and correct way to return handle bool value of Facebook, google and twitter for the above function?

1 Answers

Try this approach

func application(_ app: UIApplication, open url: URL, options: [UIApplicationOpenURLOptionsKey : Any] = [:]) -> Bool {

     let facebookDidHandle = FBSDKApplicationDelegate.sharedInstance().application(app, open: url, sourceApplication: options[UIApplicationOpenURLOptionsKey.sourceApplication] as! String!, annotation: options[UIApplicationOpenURLOptionsKey.annotation])

     let googleDidhandle = GIDSignIn.sharedInstance().handle(url, sourceApplication:options[UIApplicationOpenURLOptionsKey.sourceApplication] as? String, annotation: [:])

     let twitterDidHandle = Twitter.sharedInstance().application(app, open: url, options: options)


     return googleDidHandle || facebookDidHandle || twitterDidHandle
}
Related