Peter Lapisu Peter Lapisu - 1 month ago 23
iOS Question

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

}

}

Answer

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