Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to open phone dialler in iOS 9?

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

like image 633
Hiren Prajapati Avatar asked Mar 04 '16 09:03

Hiren Prajapati


2 Answers

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"]]];
like image 172
MOHAMMAD ISHAQ Avatar answered Oct 24 '22 07:10

MOHAMMAD ISHAQ


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];
}
like image 20
aman.sood Avatar answered Oct 24 '22 08:10

aman.sood