2

I would like to provide the functionality whereby a user can dial a phone number by tapping a button next to a label that shows the number. I have the basic button action method:

-(IBAction)Call:(id)sender{

//Define function
}

... but I don't understand how to trigger the dialing of the phone within the method.

TechZen
  • 64,370
  • 15
  • 118
  • 145
ram
  • 1,193
  • 1
  • 15
  • 27
  • possible duplicate of [dial a phone number using iOS](http://stackoverflow.com/questions/5456395/dial-a-phone-number-using-ios) – JRG-Developer Jul 19 '13 at 09:51

2 Answers2

6
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"tel://18005551234"]];
Keller
  • 17,051
  • 8
  • 55
  • 72
  • 1
    No, I don't believe this will work in Simulator, Device only. Which reminds me, you should also make sure to only perform this function if the device running the app is capable (ie, an iPhone, not iPod Touch or iPad). Check this post to see how to check the running device: http://stackoverflow.com/questions/5456395/dial-a-phone-number-using-ios – Keller Jul 10 '11 at 06:10
2

Swift 2.0:

func phoneCallPromptAction() {
    let url = NSURL(string: "telprompt://1111111111")
    UIApplication.sharedApplication().openURL(url!)
}

to ask user if he want's to call the number or just:

func phoneCallAction() {
    let url = NSURL(string: "tel://1111111111")
    UIApplication.sharedApplication().openURL(url!)
}

to make a call from you app directly.

Liubo
  • 674
  • 9
  • 18