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 than null, 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:
<key>LSApplicationQueriesSchemes</key>
<array>
<string>xxx</string>
</array>
Strange behavior that the console output looks like an error although there is none, indeed.
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.
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];
}
As iOS9 deprecates stringByAddingPercentEscapesUsingEncoding, the following can be used to clean the telprompt: URL.
NSString *cleanedString = [[[PHONE NUMBER] componentsSeparatedByCharactersInSet:[[NSCharacterSet characterSetWithCharactersInString:#"0123456789-+()"] invertedSet]] componentsJoinedByString:#""];
//NSString *escapedPhoneNumber = [cleanedString stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
NSString *escapedPhoneNumber = [cleanedString stringByAddingPercentEncodingWithAllowedCharacters: [NSCharacterSet URLQueryAllowedCharacterSet]];
NSString *phoneURLString = [NSString stringWithFormat:#"telprompt:%#", escapedPhoneNumber];
NSURL *phoneURL = [NSURL URLWithString:phoneURLString];
if ([[UIApplication sharedApplication] canOpenURL:phoneURL]) {
[[UIApplication sharedApplication] openURL:phoneURL];
}
In iOS9 I'm using this code and it works:
NSString *assistanceNumber = [[NSUserDefaults standardUserDefaults] objectForKey:#"AssistanceCallMISDN"];
assistanceNumber= [[assistanceNumber componentsSeparatedByCharactersInSet:[[NSCharacterSet characterSetWithCharactersInString:#"0123456789-+()"] invertedSet]] componentsJoinedByString:#""];
assistanceNumber = [assistanceNumber stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
NSURL *phoneUrl = [NSURL URLWithString:[#"telprompt://" stringByAppendingString:assistanceNumber]];
NSURL *phoneFallbackUrl = [NSURL URLWithString:[#"tel://" stringByAppendingString:assistanceNumber]];
if ([UIApplication.sharedApplication canOpenURL:phoneUrl]) {
[UIApplication.sharedApplication openURL:phoneUrl];
} else if ([UIApplication.sharedApplication canOpenURL:phoneFallbackUrl]) {
[UIApplication.sharedApplication openURL:phoneFallbackUrl];
} else
{
[[[UIAlertView alloc] initWithTitle:#"" message:[NSString stringWithFormat:#"No se ha podido realizar la llamada a través de la aplicación. Puede llamar usted al %#", assistanceNumber] delegate:self cancelButtonTitle:#"Ok" otherButtonTitles:nil] show];
[_viewEmergency setHidden:YES];
}
My Info.plist
<key>LSApplicationQueriesSchemes</key>
<array>
<string>telprompt</string>
<string>tel</string>
</array>
Try running this on a real device instead of simulator. No need to add LSApplicationQueriesSchemes for the tel scheme.
try this one:
NSString *phone_number = [[yourPhoneNumber componentsSeparatedByCharactersInSet:[[NSCharacterSet characterSetWithCharactersInString:#"0123456789-+()"] invertedSet]] componentsJoinedByString:#""];
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:[NSString stringWithFormat:#"telprompt://%#", phone_number]]];
Related
Im trying to create an application which will open apple maps located in iOS device with given source and destination address.
NSString* addr = [NSString stringWithFormat: #"http://maps.apple.com/?daddr=%#&saddr=%#",[_fromTextfield.text stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet URLHostAllowedCharacterSet]],[_toTextfield.text stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet URLHostAllowedCharacterSet]]];
addr=[addr stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet URLHostAllowedCharacterSet]];
NSURL* url = [NSURL URLWithString:addr];
if ([[UIApplication sharedApplication]canOpenURL:url])
{
[[UIApplication sharedApplication] openURL:url];
}
But canOpenURL is not working ! It always returns NO.
I have added
"LSApplicationQueriesSchemes
urlscheme
urlscheme2
urlscheme3
urlscheme4
"
in Info.plist file.
Try below coding.it works perfectly.
NSString* addr = [NSString stringWithFormat: #"http://maps.apple.com/?daddr=%#&saddr=%#",#"Lacock" ,#"Avebury"];
NSURL* url = [NSURL URLWithString:addr];
if ([[UIApplication sharedApplication]canOpenURL:url])
{
[[UIApplication sharedApplication] openURL:url];
}
If error is
"This app is not allowed to query for scheme whatsapp"
1) Check Info plist.
add LSApplicationQueriesSchemes Array
add whatsapp String.
If error is invalid url.
2) Check, whether the string you are passing is not having special characters. Specially whitespace.
string = [string stringByReplacingOccurrencesOfString:#" " withString:#"%20"];
then use this string for url.
Both of these should solve. Cheers!
There are many answers for this question, but on iOS 9 there are some problems. When I use this code:
NSString *phoneNumber = [#"telprompt://" stringByAppendingString:self.lblPhone.text];
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:phoneNumber]];
I got this error:
LaunchServices: ERROR: There is no registered handler for URL scheme (null)
Then I change the Info.plist with this:
<key>LSApplicationQueriesSchemes</key>
<array>
<string>telprompt</string>
<string>tel</string>
</array>
But nothing changed!
So I tried second code and this works:
NSString *numberString = #"004986632461";
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:[NSString stringWithFormat:#"telprompt://%#",numberString]]];
But this one not:
NSString *numberString = [NSString stringWithFormat:#"%f", [[_lblPhone text] floatValue]];
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:[NSString stringWithFormat:#"telprompt://%#",numberString]]];
It's dialing, but the number is wrong. Any idea?
Your second bit of code doesn't work because you are attempting to format the text as a floating point value.
This line:
NSString *numberString = [NSString stringWithFormat:#"%f", [[_lblPhone text] floatValue]];
Will result in a value of 4986632704.000000 for the string #"004986632461".
Skip the float part. Just do:
NSString *numberString = _lblPhone.text;
Don't ever try to treat a phone number as a numeric value. It's text and should only be treated (and stored) as text.
Try:
NSString *phoneNumber = [#"tel://" stringByAppendingString:self.lblPhone.text];
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:phoneNumber]];
Previously telprompt was used by most developers since it will return to app after the call while tel will return to home screen. But from iOS 8 onwards, tel will return to the app after call. So you can use that.
I solved this problem myself. It's very easy. I must clean invisible spaces!
NSString *numberString = [_lblPhone.text stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];
SCENARIO
I have an app that is a UIWebView, I make some url overriding for requirements.
PROBLEM
To make a call opening url with tel: works weird in iOS7 and iOS8, it makes the phone call direct in the background, but it also ask for the confirmation, so user experience is horrible:
[[UIApplication sharedApplication] openURL:request.URL];
SOLUTION
To solve this issue, I used telprompt. It works nice in all iOS versions:
NSURL *url = [NSURL URLWithString:#"telprompt://637****"];
return [[UIApplication sharedApplication] openURL:url];
But shows this confirmation dialog:
QUESTION
Now, I have a new requirement, to make the phone call without confirmation or prompt. So... There is some way to make a phone call in iOS omitting the confirmation prompt?
I want something like
NSURL *url = [NSURL URLWithString:#"telnoprompt://637******"];
return [[UIApplication sharedApplication] openURL:url];
NSMutableCharacterSet *characterSet =[NSMutableCharacterSet characterSetWithCharactersInString:#" "];
NSArray *arrayOfComponents = [phone_number componentsSeparatedByCharactersInSet:characterSet];
phone_number = [arrayOfComponents componentsJoinedByString:#""];
NSString *phoneURLString = [NSString stringWithFormat:#"tel:%#", phone_number];
NSString *escapedUrlString = [phoneURLString stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
NSURL *phoneURL = [NSURL URLWithString:escapedUrlString];
I've followed other questions on this however, What seems to work for them doesn't seem to work for me. I tried putting in the hard value directly into the facebookURL variable, still I get the same result. It opens the facebook app, and gives the message "The page you requested was not found".
NSDictionary *profile = [PFuserProfile objectForKey:#"profile"];
NSString *facebookId = [profile objectForKey:#"facebookId"];
NSMutableString *fullText = [NSMutableString string];
[fullText appendString:#"fb://profile/"];
[fullText appendString:facebookId];
NSURL *facebookURL = [NSURL URLWithString:fullText];
if ([[UIApplication sharedApplication] canOpenURL:facebookURL]) {
NSLog(fullText);
[[UIApplication sharedApplication] openURL:facebookURL];
} else {
NSMutableString *fullText2 = [NSMutableString string];
[fullText2 appendString: #"http://facebook.com/"];
[fullText2 appendString:facebookId];
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:fullText2]];
}
the second option, if the app isn't installed, works perfectly.
I am trying to integrate the most popular navigation apps into my app, and all of those I chose work, except for Sygic.
Following this guide, I wrote the code:
NSString *URL = [NSString stringWithFormat:#"com.sygic.aura://coordinate|%f|%f|drive",
self.coordinate.longitude,
self.coordinate.latitude];
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:URL]];
But when the code is run, Sygic doesn't open, nothing happens.
Checking [[UIApplication sharedApplication] canOpenURL:[NSURL URLWithString:#"com.sygic.aura://"]] returns YES when the app is installed and NO when it's not (as it should).
I tested using "Sygic Brasil" and "Sygic (All Regions)", version 13, but neither will open.
I also tried percent-escaping the URL string, and that didn't work either.
you try following code,
NSString *URL = [NSString stringWithFormat:#"com.sygic.aura://coordinate|%f|%f|drive",
self.coordinate.longitude,
self.coordinate.latitude];
NSURL *newURL = [NSURL URLWithString:[URL stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding] ];
if(newURL)
{
[[UIApplication sharedApplication] openURL:newURL];
}
else
{
NSLog(#"Something wrong with lat or long or both");
}