0

Hello I want the user to click on a button and the button will open the actual iPhone phone app.

Any ideas or tutorials on how to do this?

  • Why did people vote this Question down ? It's a very valid question, and was exactly what I was trying to Google. As others have mentioned, the solution is one line of code, but you could waste hours searching around the Apple documentation trying to find this gem. – Mike Gledhill Apr 24 '14 at 11:43

4 Answers4

7

You can easily place a call with this line below:

[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"tel:12125551212"]];
Brayden
  • 1,795
  • 14
  • 20
0

You can not open just Phone application to manually enter number. As suggested before you can place a call from your application which will open the default phone calling screen and once you are done with that call it will redirect back to your application.

BornCoder
  • 1,046
  • 8
  • 10
0

Just to add (without just copying & pasting the same answer yet again !) that if your phone number contains any spaces, then this line of code will silently fail.

So even if the Phone app says that it's dialling +41 44 123 4567, if you attempt to use the following line in your code, nothing will happen. It won't recognise this as a phone number.

[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"tel:+41 44 123 4567"]];

So, you need to strip out any spaces, then get the Phone app to dial the number, at which point it'll add it's own spaces back into the phone number when it displays it !!

Here's the code I've used (where the phone number is currently displayed in a UILabel called lblPhone):

 NSString* phoneNumber = [self.lblPhone.text stringByReplacingOccurrencesOfString:@" " withString:@""];

 NSString* actionStr = [NSString stringWithFormat:@"telprompt:%@", phoneNumber];

 UIDevice *device = [UIDevice currentDevice];
 if ([[device model] isEqualToString:@"iPhone"] ) {
     [[UIApplication sharedApplication] openURL:[NSURL URLWithString:actionStr]];
 } 

This code also checks whether you're running the app on an iPad. If you are, then we don't want to attempt to dial the number.

Also, as the answer on this thread suggests, you'll see that I've used telprompt: rather than tel: It has two advantages:

First, it makes a small dialog appear, to check that the user really wants to call that phone number:

Nice

And secondly, when the user finishes calling this number (and hangs up), it'll return you back into your app. Strangely, using tel: doesn't do this.

(Tested with XCode 5 & iOS 7.1)

Community
  • 1
  • 1
Mike Gledhill
  • 27,846
  • 7
  • 149
  • 159
-3
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"tel:<You button title as phone number>"]];
BornCoder
  • 1,046
  • 8
  • 10
  • Did you really find it necessary to essentially copy/paste my answer? – Brayden Aug 31 '12 at 17:56
  • It is not copy pasting my dear, I provided my way of presenting answer as you can see it. I really do not see why you have a problem if I answer just like you. – BornCoder Aug 31 '12 at 18:11
  • The only thing you changed was the numerical values to text description. If you provided a different take on the problem it'd be different, but using an existing answer to show it differently doesn't constitute as your own answer. – Brayden Aug 31 '12 at 18:20
  • Thank you for the responses, however I want the user to click the call button and it opens up the iPhone phone dialer. From there the user would manually enter in the number or select from their contacts. How do I get the button to open the iPhone phone dialer? – Niche' Ad Marketing Aug 31 '12 at 18:27