I allow my user to select phone numbers in my application. How can I then bring up the iPhone call screen and then if possible, initiate the phone call?
You can do this:
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"tel:12125551212"]];
which will create a UIAlertView prompting the user to call the number or cancel.
You can use below code
NSString *phoneNumber = @"18000275749"; // dynamically assigned
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:[NSString stringWithFormat:@"telprompt://%@",phoneNumber]]];
You'll have to recreate the dial screen within your application (didn't take too long for me to do.) Once you have the phone number entered, you'll need to initiate the phone call by doing:
NSString* theNumberYouGathered = @"9994441234";
[[UIApplication sharedApplication] openURL: [NSURL URLWithString: [NSString stringWithFormatting: @"tel:%s", theNumberYouGathered]]];
Note this will only work on the actual phone, and not the simulator.
To create the dialer screen you'll need to:
UIButton
s (for #s 1-9), a UILabel
to show the currently entered number, and a "Call" button.UIButton
s and add the digit to a local variable NSString
on your ViewController. Update the UILabel
with this number.UIButton
is pressed, take the locally stored # and place the aforementioned method call with it.