Handling different URL Schemes in iOS (Facebook and Instagram)

ardavar picture ardavar · Apr 26, 2013 · Viewed 8.6k times · Source

I am not even sure how to define the problem but here it goes.

I have an application that uses Facebook SDK for user login. I followed the Facebook authorization tutorial. I am not 100% sure how it works but this part in my "AppDelegate.m" seems important.

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

    return [FBSession.activeSession handleOpenURL:url];
}

So far so good. Now I want to implement a similar login for instagram so that the user can access their photos. I run this example without a problem (https://github.com/crino/instagram-ios-sdk). When I tried to import this into my project I got stuck. Because in instagram project there is also a function in the AppDelegate (IGAppDelegate)

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

    return [self.instagram handleOpenURL:url];
}

Now I cant use this function (since it is a duplicate of Facebook one) Is there a way to combine these two function for facebook and instagram (maybe with an "if" for different URLs). Or am I lost

PS: I noticed that when I call my facebook login app the url is something like

fb4333597123414933://authorize/#access_token=BAAGKI2vHLxUBANbDegkrdoc4GJWUZC2clqLAzxz8IxEBZBdEyjrD2oTaGZA0g2AbSGWgvEhONKM6xJWzLCALGUBguqUpor6kXu9ZBewusNZCUe6BOXYvX&expires_in=5166254

in instagram it is like:

igfd725621c5e44198a5b8ad3f7a0ffa09://authorize#access_token=354172840.fd72562.bf6b3611632d4d00b6cef660ea9d9b6f

Answer

abhi picture abhi · Feb 19, 2015
    - (BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation
    {
        NSLog(@"url: %@", [url scheme]);
        
        BOOL callBack;
        // Facebook Call back checking.
        if ([[url scheme] isEqualToString:@"facebook_url_schema"])
        {
            callBack = [FBAppCall handleOpenURL:url sourceApplication:sourceApplication];
        }
        // Instagram call back checking.
        else if ([[url scheme] isEqualToString:@"instagram_url_schema"])
        {
            callBack = [self.instagram handleOpenURL:url];
        }
        return callBack;
    }