如何使用多个 URL 处理 UIApplication handleOpenURL [英] How to handle UIApplication handleOpenURL with multiple URL's

查看:28
本文介绍了如何使用多个 URL 处理 UIApplication handleOpenURL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个应用程序将同时使用 Facebook 和 Instagram API,这两个 API 都要求我使用此委托方法:

I have an app that will be using both Facebook and Instagram API's, both of which require me to use this delegate method:

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

    return [PFFacebookUtils handleOpenURL:url];

}

这是instagram提供的代码:

and this is the code provided by instagram:

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

    return [self.instagram handleOpenURL:url];

}

如您所见,这是一个问题,因为我只能返回一个 URL 处理程序,但我需要能够决定是哪一个.

As you can see, this is a problem because I can only return one URL handler, but I need to be able to decide which one.

在我的应用程序委托中,我已经注释掉了上面的 Instagram 选项,只留下了 Facebook.正如预期的那样,Facebook 可以正常工作,但是当我在 Instagram 上点击授权时出现此错误:

In my app delegate, I have commented out the Instagram option above and left only Facebook. As expected, Facebook will work just fine, but I get this error when I tap authorize on Instagram:

显然,Facebook 正在尝试处理来自 Instagram 的返回 URL,因此它会出错.

Obviously, Facebook is trying to handle the return URL from Instagram so it will error.

检查 URL 以查看它是否包含我正在尝试的每项服务的应用 ID 是否合理?因此,如果 URL 包含 Instagram ID,则返回 Instagram 处理程序,如果包含 Facebook ID,则返回 Facebook 处理程序.

Is it plausible to check the URL to see if it contains the app ID for each service I am trying? So if URL contains the instagram ID, then return the instagram handler, if it contains the Facebook ID, then return the Facebook Handler.

任何帮助都会很棒,谢谢!

Any help would be great, thanks!

推荐答案

Facebook 和 Instagram 都让您为其服务设置了自定义 URL 方案,因此我们将使用它来过滤 URL.

Facebook and Instagram both had you setup a custom URL scheme for their services, so we will use that to filter the URL.

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

    if ([[url scheme] isEqualToString:INSTAGRAM_SCHEME])
        return [self.instagram handleOpenURL:url];

    if ([[url scheme] isEqualToString:FACEBOOK_SCHEME])
        return [PFFacebookUtils handleOpenURL:url];

    return NO;

}

定义变量的位置

#define INSTAGRAM_SCHEME @"ig12345678910"
#define FACEBOOK_SCHEME  @"fb12345678910"

与您在 Info.plist 文件中所做的完全一样

exactly as you did in your Info.plist file

这篇关于如何使用多个 URL 处理 UIApplication handleOpenURL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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