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?
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?
You can easily place a call with this line below:
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"tel:12125551212"]];
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.
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:
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)
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"tel:<You button title as phone number>"]];