views:

45

answers:

2

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?

+3  A: 

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 UIButtons (for #s 1-9), a UILabel to show the currently entered number, and a "Call" button.
  • Hook up the presses on the number UIButtons and add the digit to a local variable NSString on your ViewController. Update the UILabel with this number.
  • When the call UIButton is pressed, take the locally stored # and place the aforementioned method call with it.
sdolan
I'll test this now - but if this works I'll be very happy.thanks for replying so promptly.
WaterBoy
@WaterBoy: I just updated the answer with some of the overview steps I took to create the dialer. If you have any further questions, feel free to ask.
sdolan
It worked!thanks again
WaterBoy
+2  A: 

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.

esqew