Reputation: 727
I found solution that I need to add some code in info.plist
. I did it like below:
<key>LSApplicationQueriesSchemes</key>
<array>
<string>tel</string>
</array>
still no help. I get this error:
"-canOpenURL: failed for URL: "tel://4806501708" - error: "This app is not allowed to query for scheme tel"
my code for opening dialler:
NSString *phoneNumber = [@"tel://" stringByAppendingString:lblVenPhoneValue.text];
if ([UIApplication.sharedApplication canOpenURL:[NSURL URLWithString:phoneNumber]]) {
[UIApplication.sharedApplication openURL:[NSURL URLWithString:phoneNumber]];
What do I need to do?
Thanks in Advance
Upvotes: 7
Views: 14206
Reputation: 1298
This will not work in the simulator, but it works fine in iPhone device.
private func makeCall(number:String){ let number = "9876543210"
if let url = URL(string: "tel://\(number)"), UIApplication.shared.canOpenURL(url) {
if #available(iOS 10, *) {
UIApplication.shared.open(url)
} else {
UIApplication.shared.openURL(url)
}
}
}
Upvotes: 0
Reputation: 145
for Swift 4.0 use this(Make sure you are not on the simulator)
let cleanPhoneNumber = phone.components(separatedBy: CharacterSet.decimalDigits.inverted).joined(separator: "")
let urlString:String = "tel://\(cleanPhoneNumber)"
if let phoneCallURL = URL(string: urlString) {
if (UIApplication.shared.canOpenURL(phoneCallURL)) {
UIApplication.shared.open(phoneCallURL, options: [:], completionHandler: nil)
}
}
Upvotes: 0
Reputation: 998
Are you testing this on device ? , because this will not work on simulator . And device should have sim card too .
After confirming above try following
In info.plist
<key>LSApplicationQueriesSchemes</key>
<array>
<string>tel</string>
<string>telprompt</string>
</array>
Where want to open phone dialler
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:[NSString stringWithFormat:@"tel:%@",@"digits"]]];
or
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:[NSString stringWithFormat:@"telprompt:%@",@"digits"]]];
Upvotes: 14
Reputation: 874
just remove "//" from @"tel://" it should work
NSString *phoneNumber = [@"tel:" stringByAppendingString:lblVenPhoneValue.text];
if ([UIApplication.sharedApplication canOpenURL:[NSURL URLWithString:phoneNumber]]) {
[UIApplication.sharedApplication openURL:[NSURL URLWithString:phoneNumber]];
For more better checks you can use
if([[UIApplication sharedApplication] canOpenURL:[NSURL URLWithString:[NSString stringWithFormat:phoneNumber]]])
{
CTTelephonyNetworkInfo *networkInfo = [CTTelephonyNetworkInfo new];
CTCarrier *carrier = [networkInfo subscriberCellularProvider];
NSString *_code = [carrier mobileNetworkCode];
if(_code)
{
[[UIApplication sharedApplication] openURL:phoneNumber]];
}
else
{
UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@"no_sim" message:@"" delegate:nil cancelButtonTitle:@"ok" otherButtonTitles:nil, nil];
[alert show];
}
}
else
{
UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@"alert" message:@"alert_device_not_support" delegate:nil cancelButtonTitle:@"ok" otherButtonTitles:nil, nil];
[alert show];
}
Upvotes: 1