How can i bring up the iPhone call screen

后端 未结 3 1486
遇见更好的自我
遇见更好的自我 2020-12-22 07:20

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条回答
  •  隐瞒了意图╮
    2020-12-22 07:58

    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.

提交回复
热议问题