作者热门文章
- android - RelativeLayout 背景可绘制重叠内容
- android - 如何链接 cpufeatures lib 以获取 native android 库?
- java - OnItemClickListener 不起作用,但 OnLongItemClickListener 在自定义 ListView 中起作用
- java - Android 文件转字符串
在执行 openUrl:
以启动应回调我的应用程序的应用程序(如根据 x-callback-url 规范运行的应用程序)之前,我如何以编程方式检查我的应用程序回调是否正常工作, 在调用其他应用程序之前?
最佳答案
这是我目前的解决方案:
- (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;
}
限制是我们正在检查此应用是否注册了该方案并且一些应用程序响应该 url。
据我所知,这并不能保证您的应用程序是该方案的实际响应者(如果另一个应用程序也注册了该方案)。
根据我的尝试,iOS 似乎会为每个唯一的 url 方案打开第一个安装的应用程序。
关于iphone - 我的应用程序会响应 url 方案吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7244317/
我是一名优秀的程序员,十分优秀!