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
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"]]];
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];
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With