dji*_*i33 25 objective-c uiapplication ios ios9
我正在运行iOS 9b5.
在我的应用程序中,如果设备可以拨打电话,我想将文本颜色设置为蓝色,以便它看起来可以点亮.如果没有,我把它留黑.
为了确定设备功能,我使用:
[[UIApplcation sharedApplication] canOpenURL:@"telprompt://5555555555"]
Run Code Online (Sandbox Code Playgroud)
众所周知,iOS 9要求我们将我们将在我们的应用中使用的任何URL方案列入白名单作为隐私措施.
我在Info.plist中有这个:
<key>LSApplicationQueriesSchemes</key>
<array>
<string>telprompt</string>
</array>
Run Code Online (Sandbox Code Playgroud)
无论我做什么,我仍然得到canOpenURL:URL失败:"telprompt://" - 错误:"(null)".我试过tel://和sms://我似乎无法避免syslog警告.
有没有人知道如何检测设备是否可以在不触发这些警告的情况下拨打电话?
到目前为止我发现的是,如果控制台记录-canOpenURL: failed for URL: "xxx://" - error: "(null)",它实际上是有效的.一旦出现任何其他错误null,它可能无法正常工作.如果错误是"This app is not allowed to query for scheme xxx",那么您必须将此方案添加到您的应用程序的.plist:
<key>LSApplicationQueriesSchemes</key>
<array>
<string>xxx</string>
</array>
Run Code Online (Sandbox Code Playgroud)
确实没有控制台输出看起来像错误的奇怪行为.
我想你可能需要在实际设备上试试这个,或者再试一次.我只是在我的iPhone 5上工作,看起来你甚至不需要将它添加到LSApplicationQueriesSchemes.如果应用程序是使用Xcode 7 Beta 6构建的,并且您使用canOpenURL或openURL,如下所示它似乎在设备上运行正常.
[[UIApplication sharedApplication] canOpenURL:[NSURL URLWithString:@"tel:555-555-5555"]]
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"tel:555-555-5555"]]
在iOS sim上我仍然得到错误:
LaunchServices:错误:URL方案没有注册处理程序tel
-canOpenURL:URL失败:"tel:555-555-5555" - 错误:"此应用程序不允许查询对于计划电话"
我在IOS9设备中遇到了同样的错误.所以我使用下面的代码片段来避免这个错误.
NSString *cleanedString = [[[PHONE NUMBER] componentsSeparatedByCharactersInSet:[[NSCharacterSet characterSetWithCharactersInString:@"0123456789-+()"] invertedSet]] componentsJoinedByString:@""];
NSString *escapedPhoneNumber = [cleanedString stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
NSString *phoneURLString = [NSString stringWithFormat:@"telprompt:%@", escapedPhoneNumber];
NSURL *phoneURL = [NSURL URLWithString:phoneURLString];
if ([[UIApplication sharedApplication] canOpenURL:phoneURL]) {
[[UIApplication sharedApplication] openURL:phoneURL];
}
Run Code Online (Sandbox Code Playgroud)