问题描述
我将使用Facebook和Instagram的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的提供的code:
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.
是不是合理查询的网址,看它是否包含了每个服务我想要的应用程序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;
}
如果你定义变量作为
Where you define your variables as
#define INSTAGRAM_SCHEME @"ig12345678910"
#define FACEBOOK_SCHEME @"fb12345678910"
完全按照您在没有你的的Info.plist
文件
这篇关于如何处理的UIApplication handleOpenURL多个网址的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!