How can i bring up the iPhone call screen
I allow my user to selec开发者_运维问答t phone numbers in my application. How can I then bring up the iPhone call screen and then if possible, initiate the phone call?
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:
- Create a xib file with a set of
UIButton
s (for #s 1-9), aUILabel
to show the currently entered number, and a "Call" button. - Hook up the presses on the number
UIButton
s and add the digit to a local variableNSString
on your ViewController. Update theUILabel
with this number. - When the call
UIButton
is pressed, take the locally stored # and place the aforementioned method call with it.
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]]];
精彩评论