Martin Christov Martin Christov - 2 months ago 15
Objective-C Question

Integrating Facebook & Google login on iOS react-native - AppDelegate.m callback function

There are two aspects of the problem of integrating both google & facebook login within AppDelegate.m:

I. Handling the opening conditionally, which I managed via the following:

- (BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation {

NSString *stringURL = [ url absoluteString];

if([stringURL containsString:@"fb"])
return [[FBSDKApplicationDelegate sharedInstance] application:application
openURL:url
sourceApplication:sourceApplication
annotation:annotation];
else return [[GIDSignIn sharedInstance] handleURL:url
sourceApplication:sourceApplication
annotation:annotation];

}


II. Handling the callback after user has logged in.
This, I was unable to do with both working simultaneously. Either one or the other gets disabled.
The code snippets for them are as follows:

// Facebook SDK
- (void)applicationDidBecomeActive:(UIApplication *)application {
[FBSDKAppEvents activateApp];
}

// Google
- (BOOL)application:(UIApplication *)application
openURL:(NSURL *)url
options:(NSDictionary<UIApplicationOpenURLOptionsKey,id> *)options {
BOOL handled = [[GIDSignIn sharedInstance] handleURL:url
sourceApplication:options[UIApplicationOpenURLOptionsSourceApplicationKey]
annotation:options[UIApplicationOpenURLOptionsAnnotationKey]];
return handled;
}


If I delete the last part Facebook callback works.
But I really want both to work :)
Can someone help?

Answer Source

You can check like this

in didFinishLaunchingWithOptions method

[[FBSDKApplicationDelegate sharedInstance] application:application
                             didFinishLaunchingWithOptions:launchOptions];

for handling FACEBOOK

#pragma -mark
#pragma -mark FACEBOOK Sign-In configuration

- (BOOL)application:(UIApplication *)application openURL:(NSURL *)url
  sourceApplication:(NSString *)sourceApplication annotation:(id)annotation {

    BOOL handled = [[FBSDKApplicationDelegate sharedInstance] application:application
                                                                  openURL:url
                                                        sourceApplication:sourceApplication
                                                               annotation:annotation
                    ];
    // Add any custom logic here.

    return handled;
}



- (BOOL)application:(UIApplication *)app
                openURL:(NSURL *)url
                options:(NSDictionary *)options {


    if ([[url scheme] isEqualToString:@"fb*************"]) {
        return [[FBSDKApplicationDelegate sharedInstance] application:app
                                                              openURL:url
                                                    sourceApplication:options[UIApplicationOpenURLOptionsSourceApplicationKey]
                                                           annotation:options[UIApplicationOpenURLOptionsAnnotationKey]];

    }else
    {

        return [[GIDSignIn sharedInstance] handleURL:url
                                   sourceApplication:options[UIApplicationOpenURLOptionsSourceApplicationKey]
                                          annotation:options[UIApplicationOpenURLOptionsAnnotationKey]];
    }
}