简体   繁体   中英

iOS: Action Method to Dial Phone Number Upon User Tapping a Button

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.

[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"tel://18005551234"]];

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM