Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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?

like image 397
Anant Kaushik Avatar asked Jan 30 '23 05:01

Anant Kaushik


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
}
like image 164
GIJOW Avatar answered Jan 31 '23 22:01

GIJOW