Joã*_*ela 7 iphone objective-c ios x-callback-url
在openUrl:启动应该回调我的应用程序的应用程序之前(就像根据x-callback-url规范行事的应用程序),在调用其他应用程序之前,如何以编程方式检查我的应用程序回调是否正常?
Joã*_*ela 12
这是我目前的解决方案:
- (BOOL) respondsToUrl:url
{
BOOL schemeIsInPlist = NO; // find out if the sceme is in the plist file.
NSBundle* mainBundle = [NSBundle mainBundle];
NSArray* cfBundleURLTypes = [mainBundle objectForInfoDictionaryKey:@"CFBundleURLTypes"];
if ([cfBundleURLTypes isKindOfClass:[NSArray class]] && [cfBundleURLTypes lastObject]) {
NSDictionary* cfBundleURLTypes0 = [cfBundleURLTypes objectAtIndex:0];
if ([cfBundleURLTypes0 isKindOfClass:[NSDictionary class]]) {
NSArray* cfBundleURLSchemes = [cfBundleURLTypes0 objectForKey:@"CFBundleURLSchemes"];
if ([cfBundleURLSchemes isKindOfClass:[NSArray class]]) {
for (NSString* scheme in cfBundleURLSchemes) {
if ([scheme isKindOfClass:[NSString class]] && [url hasPrefix:scheme]) {
schemeIsInPlist = YES;
break;
}
}
}
}
}
BOOL canOpenUrl = [[UIApplication sharedApplication] canOpenURL:[NSURL URLWithString: url]];
return schemeIsInPlist && canOpenUrl;
}
Run Code Online (Sandbox Code Playgroud)
限制是我们正在检查此应用程序是否为该方案注册,并且某些应用程序响应该URL.
AFAIK这并不保证您的应用程序是该方案的实际响应者(在另一个应用程序也注册该方案的情况下).
根据我的尝试,似乎iOS为每个独特的url方案打开了第一个安装的应用程序.
| 归档时间: |
|
| 查看次数: |
4040 次 |
| 最近记录: |