Search code examples
iosfacebookcocoa-touchoauth-2.0

Handling openURL: with Facebook and Google


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];

    }

}

Solution

  • 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;
    }