user in my app can login using 2 services : Facebook or Google
everything works fine, however, in the :
- (BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation: (id)annotation { ... }
i should decide to call the Facebook callback or Google callback
if the user has the apps, its easy, than i decide by the sourceApplication but when not (no native Facebook account linked in, no FB app, no GooglePlus app), it links to the browser :( and i dont know if it is comming from Facebook or Google
is there a way how to decide what to call? like
- (BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation: (id)annotation { // how to decide? if (facebook) { return [FBSession.activeSession handleOpenURL:url]; } else if (google) { return [GPPURLHandler handleURL:url sourceApplication:sourceApplication annotation:annotation]; } }
We don't need to Explicitly check the URL, the code below does it:
- (BOOL)application: (UIApplication *)application openURL: (NSURL *)url sourceApplication: (NSString *)sourceApplication annotation: (id)annotation { if ([GPPURLHandler handleURL:url sourceApplication:sourceApplication annotation:annotation]) { return YES; }else if([FBAppCall handleOpenURL:url sourceApplication:sourceApplication]){ return YES; } return NO; }
For Swift users, (The idea from user2144179)
Import below frameworks
import Firebase import GoogleSignIn import FacebookCore // (FBSDKCore's alternative for swift)
and in your delegate methods
// when your target is under iOS 9.0 func application(_ application: UIApplication, open url: URL, sourceApplication: String?, annotation: Any) -> Bool { let isFBOpenUrl = SDKApplicationDelegate.shared.application(application, open: url, sourceApplication: sourceApplication, annotation: annotation) let isGoogleOpenUrl = GIDSignIn.sharedInstance().handle(url, sourceApplication: sourceApplication, annotation: annotation) if isFBOpenUrl { return true } if isGoogleOpenUrl { return true } return false }
or you can use another 'open url:' method if your target is 9.0+. SDKs include a method for it also.
Firebase Reference : https://firebase.google.com/docs/auth/ios/google-signin
Facebook Reference : https://developers.facebook.com/docs/swift/reference/classes/applicationdelegate.html
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