iOS Call code

Source: Internet
Author: User

Define actions When you click the Dial button

-(void) callaction{

NSString *number = @ "";//Here the phone number is read in

NSString *num = [[NSString alloc] initwithformat:@ "tel://%@", number]; Number is a string if you end the call using this method, the contact list is entered

NSString *num = [[NSString alloc] initwithformat:@ "telprompt://%@", number]; And this method is to call before the frame whether to call and then after the call back to the program online said this method may not be legal audit

[[UIApplication sharedapplication] Openurl:[nsurl Urlwithstring:num]]; Dial

}

The following code can add a phone button to the app and tap to call the phone number. It's also useful for iPhone developers.

Add Phone icon button

UIButton *btnphone = [[UIButton buttonwithtype:uibuttontyperoundedrect] retain];

Btnphone.frame = CGRectMake (280,10,30,30);

[Btnphone Setbackgroundcolor:[uicolor Redcolor];

Tap the Dial button to dial directly

[Btnphone addtarget:self Action: @selector (Callaction) forcontrolevents:uicontroleventtouchupinside];

[Self.window Addsubview:btnphone];

The third way to call

-(void) callphone{

NSString *phonenum = @ "";//Telephone number

Nsurl *phoneurl = [Nsurl urlwithstring:[nsstring stringwithformat:@ "tel:%@", Phonenum]];

if (!phonecallwebview) {

Phonecallwebview = [[UIWebView alloc] initwithframe:cgrectzero];//This webview is just a backstage easy no need to add to the page effect is the same as method two but this method is legal

}

[Phonecallwebview loadrequest:[nsurlrequest Requestwithurl:phoneurl];

}

iOS Call code

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.