how to open phone dialler in iOS 9?
Asked Answered
R

4

7

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

Radiochemistry answered 4/3, 2016 at 9:43 Comment(9)
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:[NSString stringWithFormat:@"tel:%@",@"digits"]]]; try this , without "//"Daukas
NSString *phoneNumber = [@"telprompt://" stringByAppendingString:@number]; [[UIApplication sharedApplication] openURL:[NSURL URLWithString:phoneNumber]]; check this too if above not workDaukas
no luck. still getting : "This app is not allowed to query for scheme telprompt"Radiochemistry
is my info.plist correct? here it isRadiochemistry
telprompt try this in info.plistDaukas
are you testing this on device ? , because this will not work on simulator . And device should have sim card too .Daukas
<dict> <key>CFBundleDevelopmentRegion</key> <string>en</string> <key>CFBundleExecutable</key> <string>$(EXECUTABLE_NAME)</string> <key>CFBundleIdentifier</key> <string>$(PRODUCT_BUNDLE_IDENTIFIER)</string> <key>CFBundleInfoDictionaryVersion</key> <string>6.0</string> <key>CFBundleName</key> <string>$(PRODUCT_NAME)</string> <key>CFBundleSignature</key> <string>????</string> <key>CFBundleVersion</key> <string>1</string> <key>LSApplicationQueriesSchemes</key> <array> <string>tel</string> <string>telprompt</string> </array> </dict> </plist>Radiochemistry
I forgot to mention that i use simulator. Maybe thats the reason of failure. I should check on device.Radiochemistry
everything seems ok , You should test on device (with sim card)Daukas
D
14

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"]]];
Daukas answered 4/3, 2016 at 10:54 Comment(1)
without adding LSApplicationQueriesSchemes also it works fineOrson
S
1

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];
}
Syntactics answered 4/3, 2016 at 10:15 Comment(2)
I forgot to mention that i use simulator. Maybe thats the reason of failure. I should check on device.Radiochemistry
ohh. That should be the reason, then you should add check/alert for such conditionsSyntactics
C
0

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)
            }
        }
Claudianus answered 26/9, 2018 at 7:19 Comment(0)
N
0

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)
        }
    }
}
Niobic answered 3/5, 2019 at 10:28 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.