I'm running iOS 9b5.
In my app, if a device can make a phone call, I want to color the text blue so it looks tappable. If not, I leave it black.
In order to determine the device capabilities, I use:
[[UIApplcation sharedApplication] canOpenURL:@"telprompt://5555555555"]
As we all know, iOS 9 requires we whitelist any URL schemes we'll be using in our app as a privacy measure.
I have this in my Info.plist:
<key>LSApplicationQueriesSchemes</key>
<array>
<string>telprompt</string>
</array>
No matter what I do, I still get canOpenURL: failed for URL: "telprompt://" - error: "(null)". I've tried tel:// and sms:// and I can't seem to avoid that syslog warning.
Does anybody know of a way to detect whether or not a device can make a phone call wtihout triggering these warnings?
What I discovered so far is, that if the console logs
-canOpenURL: failed for URL: "xxx://" - error: "(null)"
, it actually works. As soon as there is any other error thannull
, it may not work. If the error is"This app is not allowed to query for scheme xxx"
, then you have to add this scheme to your app's .plist:Strange behavior that the console output looks like an error although there is none, indeed.
try this one:
In iOS9 I'm using this code and it works:
My Info.plist
As iOS9 deprecates stringByAddingPercentEscapesUsingEncoding, the following can be used to clean the telprompt: URL.
I think you might need to try this on an actual device, or just try it again. I just got this working on my iPhone 5, it looks like you don't even need to add it to the LSApplicationQueriesSchemes. If the app is built with Xcode 7 Beta 6 and you use canOpenURL or openURL like below it seems to work just fine on device.
[[UIApplication sharedApplication] canOpenURL:[NSURL URLWithString:@"tel:555-555-5555"]]
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"tel:555-555-5555"]]
On the iOS sim I still get the error:
LaunchServices: ERROR: There is no registered handler for URL scheme tel
-canOpenURL: failed for URL: "tel:555-555-5555" - error: "This app is not allowed to query for scheme tel"
I got the same error in IOS9 devices. So I have used below code snippet to avoid this error.