Jick Lick
Jick Lick

Reputation: 61

What’s the correct URL for placing a call on an iPhone?

Is the code for calling on the iPhone automatically

[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"tel:11111111111"]]);

Upvotes: 5

Views: 3597

Answers (5)

mythicalcoder
mythicalcoder

Reputation: 3291

SwiftArchitect's answer doesn't fit all. I wanted to actually initiate an automatic call, not prompt.

So there is a difference between tel and telprompt.

tel: actually initiates the call.

if let url = URL(string: "tel:\(phoneNumber)") {
  if UIApplication.shared.canOpenURL(url) {
    UIApplication.shared.openURL(url)
  }
}

telprompt: prompts for call or cancel.

if let url = URL(string: "telprompt:\(phoneNumber)") {
  if UIApplication.shared.canOpenURL(url) {
    UIApplication.shared.openURL(url)
  }
}

I didn't know the difference. Question also asks for calling. So this kind of answer would have helped me save time.

Upvotes: 0

SwiftArchitect
SwiftArchitect

Reputation: 48514

Too many answers with conflicting comments.

(slash, no slash, semicolumn, tel, telprompt ?)

Swift, one size fits all:

if let phoneURL = NSURL(string: "telprompt:\(phoneNumber)") {
    if UIApplication.sharedApplication().canOpenURL(phoneURL) {
        UIApplication.sharedApplication().openURL(phoneURL)
    }
}

Upvotes: 0

Nitin Gohel
Nitin Gohel

Reputation: 49720

you can only call from Iphone device not from ipad/ipod, and you can dial number from iphone like bellow code:-

NSString *value=@"your number";
NSURL *url = [[ NSURL alloc ] initWithString:[NSString stringWithFormat:@"tel://%@",value]];
[[UIApplication sharedApplication] openURL:url]; 

Upvotes: 4

Janak Nirmal
Janak Nirmal

Reputation: 22726

Your second line is fine and will work.

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

Upvotes: 8

zoul
zoul

Reputation: 104065

From trying on an iPhone, tel://123456789 is the way to go. The tel:123456789 option is not even recognized, at least by the Safari URL bar.

Upvotes: 4

Related Questions