Handling openURL: with Facebook and Google

facebook login swift 4 tutorial
facebook ios login
custom facebook login button swift
facebook sdk swift
firebase google sign in ios
presentingviewcontroller must be set google sign in
the user has not signed in before or they have since signed out.

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 need to check the URL, below code 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;

iOS - Facebook Login, user in my app can login using 2 services : Facebook or Google. everything works fine, however, in the : - (BOOL)application:(UIApplication  Google Maps URL Scheme for iOS On device running iOS 9 and later, you can use Universal Links to launch Google Maps when you have a Google Maps URL. You can use the Google Maps URL scheme to launch the Google Maps app for iOS and perform searches, get direction requests, and display map views.

You can Try the following :

if ([[url absoluteString] rangeOfString:@"<Your Google Bundle ID>"].location ==            NSNotFound)
    // Call FBAppCall's handleOpenURL:sourceApplication to handle Facebook app responses
    BOOL wasHandled = [FBAppCall handleOpenURL:url sourceApplication:sourceApplication];
    // You can add your app-specific url handling code here if needed
    return wasHandled;
    return [GPPURLHandler handleURL:url
return YES;

Call the above method in

(BOOL)application:(UIApplication *)application
          openURL:(NSURL *)url
sourceApplication:(NSString *)sourceApplication

in your appDelegeate.m

Basically what this is going to do is examine the url prefix and then call the google+ method if url prefix is ur google+ bundle id , and if not , it'll call the fb method . Hope this helps

Integrating Google Sign-In into your iOS app, user in my app can login using 2 services : Facebook or Google. everything works fine, however, in the : - (BOOL)application:(UIApplication  Handling Android App Links Users following links on devices have one goal in mind: to get to the content they want to see. As a developer, you can set up Android App Links to take users to a link's specific content directly in your app, bypassing the app-selection dialog, also known as the disambiguation dialog.

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

Swift 3: Firebase Social Login, Implement the application:openURL:options: method of your app which will properly handle the URL that your application receives at the end  Facebook is showing information to help you better understand the purpose of a Page. See actions taken by the people who manage and post content. Confirmed Page Owner: Google Inc.

The method "application:openURL:sourceApplication:annotation:" is deprecated from iOS9. so now you can use like.

- (BOOL)application:(UIApplication *)app
        openURL:(NSURL *)url
        options:(NSDictionary *)options {
       // For Google sign in SDK
       if ([[GIDSignIn sharedInstance] handleURL:url
                                      annotation:options[UIApplicationOpenURLOptionsAnnotationKey]]) {
          return YES;
       // For Facebook SDK
       }else if ( [[FBSDKApplicationDelegate sharedInstance] application:app
          return YES;
      //For Google plus SDK
      }else if ([GPPURLHandler handleURL:url
          return YES;

     return NO;

iOS 13 cannot login · Issue #1067 · facebook/facebook-ios-sdk , Google Sign In. 23:53 Swift 3: Firebase Social Login - Facebook Authentication and Cocoapods OpenURLOptionsKey : Any]) -> Bool { let handled  Google allows users to search the Web for images, news, products, video, and other content.

You can try this for a Swift 4.2 version:

func application(_ app: UIApplication, open url: URL, options: [UIApplicationOpenURLOptionsKey : Any] = [:]) -> Bool 
    if (url.scheme?.hasPrefix("fb"))! {
        return SDKApplicationDelegate.shared.application(app, open: url, options: options)
        return GIDSignIn.sharedInstance().handle(url as URL?, sourceApplication: options[UIApplicationOpenURLOptionsKey.sourceApplication] as? String,
                                                                 annotation: options[UIApplicationOpenURLOptionsKey.annotation])

Easily add sign-in to your iOS app with FirebaseUI, Goals. I want my users to login to my app through Facebook login. OpenURLOptionsKey : Any] = [:]) -> Bool with iOS 13 options no longer contain the key . method is not called and therefore the login cannot be handled. Log into Facebook to start sharing and connecting with your friends, family, and people you know.

Receive Dynamic Links on iOS - Firebase, If you enabled Google or Facebook sign-in, implement a handler for the result of the Google and func application(_ app: UIApplication, open url: URL, options:  Create an account or log into Facebook. Connect with friends, family and other people you know. Share photos and videos, send messages and get updates.

Xamarin.Essentials: Web Authenticator, Finally, in the application:openURL:sourceApplication:annotation: (iOS 8 and older) and application:openURL:options: (iOS 9 and up) methods, handle links  Handling Google Sheet can be a horrible nightmare, but it can be fun if you know these tips and tricks. Here are the 5 tips and tricks that you should try now in Google Sheet. Thank you for your constant support, and let's do more to inspire everyone! 💕 If you like our content, please consider the following 😊:

You should consider implementing Android App Links to handle the callback URI and ensure your Apple, Microsoft, Google, Facebook, etc. Search the world's information, including webpages, images, videos and more. Google has many special features to help you find exactly what you're looking for.

  • You could alternately test that the URL's scheme starts with "fb", which would make the code app ID independent.
  • Genius, I could not for the life of me figure out why only FB OR G+ was working, never both at the same time
  • Though it gives the solution for the answer. It would be good to explain the code
  • thats i belive wrong code, becasue both Google and Facebook handle the url in all cases... it should be conditional, like in the accepted answer
  • Added prefix check for a facebook URL
  • canOpenURL first of all, allows you to tell which apps are installed on the device. You can inspect the URL's prefix to figure out which service it came from. URLs for Facebook's app will start with fb:
  • @Idles remember that this is the callback method. If your app supports both facebook and google urls, canOpenUrl always returns YES for both. You're right that you can inspect the url, but usually a library has a handleURL: method that returns a boolean for you. You wouldn't have to bother yourself unless you want to do magic yourself.