27

I'm trying to call a phone number from ios app using: It's not working, although the method gets called:

-(IBAction)callPhone:(id)sender {

        NSString *phoneCallNum = [NSString stringWithFormat:@"tel://%@",listingPhoneNumber ];

        [[UIApplication sharedApplication] openURL:[NSURL URLWithString:phoneCallNum]];

        NSLog(@"phone btn touch %@", phoneCallNum);
    }

NSLog output: phone btn touch tel://+39 0668806972

Divya Bhaloidiya
  • 5,018
  • 2
  • 25
  • 45
user2588945
  • 1,681
  • 6
  • 25
  • 38
  • 1
    please check this:- http://stackoverflow.com/questions/13306293/whats-the-correct-url-for-placing-a-call-on-an-iphone/13306894#13306894 – Nitin Gohel Sep 20 '13 at 10:10
  • also check: http://stackoverflow.com/questions/4582327/how-to-make-a-call-programmatically – Preetam Jadakar Sep 20 '13 at 10:11
  • Checkout _Native app URL string_ bullet: https://developer.apple.com/library/ios/featuredarticles/iPhoneURLScheme_Reference/PhoneLinks/PhoneLinks.html#//apple_ref/doc/uid/TP40007899-CH6-SW1 – dvp.petrov Apr 28 '16 at 14:58

5 Answers5

89

your code is correct. did you check in real device. this function will not work in simulator.

try this also,

NSString *phNo = @"+919876543210";
NSURL *phoneUrl = [NSURL URLWithString:[NSString  stringWithFormat:@"telprompt:%@",phNo]];

    if ([[UIApplication sharedApplication] canOpenURL:phoneUrl]) {
        [[UIApplication sharedApplication] openURL:phoneUrl];
    } else
    {
        calert = [[UIAlertView alloc]initWithTitle:@"Alert" message:@"Call facility is not available!!!" delegate:nil cancelButtonTitle:@"ok" otherButtonTitles:nil, nil];
        [calert show];
    }

** Swift 3 version**

if let url = URL(string: "telprompt:\(phoneNumber)") {
  if UIApplication.shared.canOpenURL(url) {
    UIApplication.shared.open(call, options: []) { result in
       // do something with result
    }
  }
}
Sandeep Rana
  • 3,251
  • 2
  • 24
  • 38
Yas
  • 1,064
  • 9
  • 13
  • thanks! I tried with the phone number you provided and it works. perhaps it's my phone number formatting. With mine I get "Call facility is not available!!!" could my number be off because of the + as in: +39 0668806972 – user2588945 Sep 20 '13 at 10:31
  • 3
    my problem was the whitespace that I stripped out. then it worked. thanks! – user2588945 Sep 20 '13 at 11:01
  • `telprompt:` is not official and it may be both removed in future versions or your app may be rejected. – Nat Apr 03 '15 at 10:37
  • 4
    Hey you are missing // after telprompt:-----Should be telprompt:// . -1 for being careless. Took quite sometime for me to find the problem. :P – Prajeet Shrestha May 11 '15 at 01:23
14

Telephony does not work on simulators/iPod/iPad, you will require to run the app on an iPhone with active sim card.

Also the URL scheme to invoke the telephony application is tel:<phone_number>. Refer Apple docs.

Ideally, you should check if the device is having the telephony module and then perform the openURL: call. Use this code to perform the check,

if([[UIApplication sharedApplication] canOpenURL:callUrl]) {
    [[UIApplication sharedApplication] openURL:callUrl];
}
else {
    //Show error message to user, etc.
}
valarMorghulis
  • 302
  • 1
  • 12
Amar
  • 13,202
  • 7
  • 53
  • 71
5

Use following method to make call:

 NSString *phoneNumber = [@"tel://" stringByAppendingString:number];
 [[UIApplication sharedApplication] openURL:[NSURL URLWithString:phoneNumber]];
Divya Bhaloidiya
  • 5,018
  • 2
  • 25
  • 45
  • 1
    Be aware that the `telprompt:` is not a official scheme and can therefor be removed from iOS in future versions. – rckoenes Sep 20 '13 at 10:15
0

You can try like below.

NSString *phoneNumber = [@"tel://" stringByAppendingString:Number];
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:phoneNumber]];

Hope it helps you.

Manthan
  • 3,856
  • 1
  • 27
  • 58
0
 NSString *phoneNumber = [@"tel://" stringByAppendingString:@"9414481799"];
 [[UIApplication sharedApplication] openURL:[NSURL URLWithString:phoneNumber]];

This will only run on device.

kshitij godara
  • 1,523
  • 18
  • 30