在 iOS 中处理不同的 URL Schemes(Facebook 和 Instagram) [英] Handling different URL Schemes in iOS (Facebook and Instagram)

查看:24
本文介绍了在 iOS 中处理不同的 URL Schemes(Facebook 和 Instagram)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我什至不知道如何定义问题,但问题就在这里.

我有一个使用 Facebook SDK 进行用户登录的应用程序.我遵循了 Facebook 授权教程.我不是 100% 确定它是如何工作的,但我的AppDelegate.m"中的这部分似乎很重要.

- (BOOL)application:(UIApplication *)applicationopenURL:(NSURL *)url源应用程序:(NSString *)源应用程序注释:(id)注释{返回 [FBSession.activeSession handleOpenURL:url];}

到目前为止一切顺利.现在我想为 instagram 实现类似的登录,以便用户可以访问他们的照片.我运行这个例子没有问题(https://github.com/crino/instagram-ios-sdk).当我尝试将其导入我的项目时,我被卡住了.因为在instagram项目中AppDelegate(IGAppDelegate)中也有一个函数

-(BOOL)application:(UIApplication *)applicationopenURL:(NSURL *)url源应用程序:(NSString *)源应用程序注释:(id)注释{返回 [self.instagram handleOpenURL:url];}

现在我不能使用这个功能(因为它是 Facebook 的副本)有没有办法将这两个功能结合到 facebook 和 instagram(对于不同的 URL 可能有一个if").还是我迷路了

PS:我注意到当我调用我的 facebook 登录应用程序时,url 类似于

fb4333597123414933://authorize/#access_token=BAAGKI2vHLxUBANbDegkrdoc4GJWUZC2clqLAzxz8IxEBZBdEyjrD2oTaGZA0g2AbSGWgvEhWUBq6eXpXuXpXuXpXuGypXuX5GvEhWQuZ6ypXuXpXuGypXuGuXpXuGypXuGuXpZ6ypXuGuXpXuGuXuGuXuGuXpZ6ypX6

instagram 是这样的:

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

解决方案

 - (BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)注解{NSLog(@"url: %@", [url scheme]);布尔回调;//Facebook 回调检查.if ([[url scheme] isEqualToString:@"facebook_url_schema"]){callBack = [FBAppCall handleOpenURL:url sourceApplication:sourceApplication];}//Instagram 回调检查.else if ([[url scheme] isEqualToString:@instagram_url_schema"]){callBack = [self.instagram handleOpenURL:url];}返回回调;}

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

解决方案

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

这篇关于在 iOS 中处理不同的 URL Schemes(Facebook 和 Instagram)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆