PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Wednesday, June 29, 2022

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

 June 29, 2022     facebook, facebook-sdk-4.0, ios, swift, twitter     No comments   

Issue

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?


Solution

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
}


Answered By - GIJOW
Answer Checked By - Dawn Plyler (PHPFixing Volunteer)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing