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?
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
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With