App calls & text messages & Email

Source: Internet
Author: User

In mobile development we will often need to call phone calls, text messaging and email functions, the following is my summary of the method:
1. Call//Method 1 The most commonly used method nsurl *telurl = [Nsurl urlwithstring: "tel://13161906451"]; UIWebView *webview = [[UIWebView alloc] Initwithframe:cgrectzero]; [WebView loadrequest:[nsurlrequest requestwithurl:telurl]];//Method 2 Cons: This method stops after the call ends in the dial-up interface Nsurl *telurl = [Nsurl URLWithString: "tel://13161906451"]; [[UIApplication Sharedapplication] openurl:telurl];//Method 3 before making a call will ask the user whether to dial, hang up the phone will return to the app #warn not be used, audit does not pass, private apinsurl * TELURL2 = [Nsurl urlwithstring: "telprompt://13161906451"]; [[UIApplication sharedapplication] OPENURL:TELURL2];//2. e-mail//method 1//If you want to specify the content of the message, you have to use the MESSAGEUI framework//contains the main header file #import < messageui/messageui.h>//Cannot send mail if (![ Mfmailcomposeviewcontroller Cansendmail]) return;//return to the original program after the message was sent successfully or failed or canceled mfmailcomposeviewcontroller *VC = [[ Mfmailcomposeviewcontroller Alloc] init];//set message subject [VC setsubject:@ "Meeting"];//set message content [VC setmessagebody:@] meeting this afternoon "ishtml : no];//set recipient list [VC settorecipients:@[@ "[email protected]"]];//set cc people list [VC setccrecipients:@[@ "[email  Protected] "]];//set up a BCC list [VC setbccrecipients:@[@"[email protected]"]];//add attachment (one picture) UIImage *image = [UIImage imagenamed:@ "Lufy.jpeg"]; NSData *data = uiimagejpegrepresentation (image, 0.5);//Go to Baidu on search MIMETYPE[VC addattachmentdata:data mimetype:@ "Image/jepg "filename:@" Lufy.jpeg "];//set proxy vc.mailcomposedelegate = self;//display Controller [self presentviewcontroller];//proxy method callback after message sent, will automatically return to the original application-(void) Mailcomposecontroller: (Mfmailcomposeviewcontroller *) controller didfinishwithresult: ( Mfmailcomposeresult) Result Error: (NSERROR *) error{//Close Mail interface [controller Dismissviewcontrolleranimated:yes completio        N:nil];    if (result = = mfmailcomposeresultcancelled) {NSLog (@ "Cancel send");    } else if (result = = Mfmailcomposeresultsent) {NSLog (@ "already issued");    } else {NSLog (@ "send failed"); }}//Method 2 Disadvantage: Does not return application nsurl *emailurl = [Nsurl urlwithstring: "mailto://[email protected]"]; [[UIApplication sharedapplication] OPENURL:EMAILURL];//3. SMS//Method 1//If you want to specify a text message, you have to use the Messageui frame//contains the main header file #import < messageui/messageui.h>//If you can not send a direct return, the simulator can not send text messages, tuneTexting will crash if (![ Mfmessagecomposeviewcontroller Cansendtext]) return;//shows the controller that sent the text message mfmessagecomposeviewcontroller *VC = [[ Mfmessagecomposeviewcontroller alloc] init];//Set SMS content vc.body = @ "Have you eaten yet?" ";///Set the recipient list vc.recipients = @[@" 10010 ", @" 02010010 "];//set up the proxy, this proxy causes the Cancel button to appear in the upper-right corner vc.messagecomposedelegate = self;//display Controller [ Self PRESENTVIEWCONTROLLER:VC animated:yes completion:nil];//proxy method, when the SMS interface is closed when the call, after the end will automatically return to the original application-(void) Messagecomposeviewcontroller: (Mfmessagecomposeviewcontroller *) controller didfinishwithresult: (        Messagecomposeresult) result{//Close SMS interface [controller Dismissviewcontrolleranimated:yes Completion:nil];    if (result = = messagecomposeresultcancelled) {NSLog (@ "Cancel send");    } else if (result = = Messagecomposeresultsent) {NSLog (@ "already issued");    } else {NSLog (@ "send failed"); }}//display controller [self PRESENTVIEWCONTROLLER:VC animated:yes completion:nil];//Method 2 Disadvantage: cannot return to app after send end nsurl *smslurl = [Nsurl URLW Ithstring: "sms://13161906451"]; [[UIApplication sharedapplication] openurl:smslurl];

App calls & text messages & Email

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.