3-ios-Small function (call, send text, send e-mail)

Source: Internet
Author: User

Many of the small features in iOS are simple, with a few lines of code, such as calling, opening URLs, sending emails, texting, etc.First, call1> the simplest and most straightforward way: jump directly to the dial-up interface
Nsurl *url = [Nsurl urlwithstring:@ "tel://10010"];
[[UIApplication sharedapplication] openurl:url];
disadvantage: After the call is finished, will not automatically return to the original application, directly stay in the call log interface

2> before dialing the box asks the user whether to dial, can automatically return to the original application after the dial is finished
Nsurl *url = [Nsurl urlwithstring:@ "telprompt://10010"];
[[UIApplication sharedapplication] openurl:url];
Disadvantages:because it is a private API, it may not be approved, it is recommended not to use

3> Create a UIWebView to load the URL, and automatically return to the original application after the dial is finished
if (_webview = = nil) {
_webview = [[UIWebView alloc] Initwithframe:cgrectzero];
}
[_webview loadrequest:[nsurlrequest requestwithurl:[nsurl urlwithstring:@ "tel://10010"]];
Note: This webview must not be added to the interface, or it will block other interfaces

Second, send SMS

1> Texting 1

*url = [Nsurl urlwithstring:@ "sms://10010"];[ [UIApplication sharedapplication] openurl:url];

2> If you want to specify a text message, you have to use the MESSAGEUI framework

include primary header file#import<MessageUI/MessageUI.h>before calling the text message code, it is best to determine whether the user's device can send text messages//can't send text messagesif(! [Mfmessagecomposeviewcontroller Cansendtext])returnDisplay the SMS controller Mfmessagecomposeviewcontroller*VC =[[Mfmessagecomposeviewcontroller alloc] init];//Set SMS ContentVc.body =@"did you have dinner? ";//set up a recipient listVc.recipients = @[@"10010",@"02010010"];//Set up proxyVc.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 the SMS interface[Controller Dismissviewcontrolleranimated:yes Completion:nil]; if(Result = =messagecomposeresultcancelled) {NSLog (@"Cancel Send"); } Else if(Result = =messagecomposeresultsent) {NSLog (@"has been issued"); } Else{NSLog (@"Send failed"); }}

Third, send an e-mail

1> with your own mail client, will not automatically return to the original application after sending the message

*url = [Nsurl urlwithstring:@ "mailto://[email protected]"];[ [UIApplication sharedapplication] openurl:url];

2> is similar to the 2nd method of texting, except that the controller class name is called: Mfmailcomposeviewcontroller

//Cannot send mailif(! [Mfmailcomposeviewcontroller Cansendmail])return; Mfmailcomposeviewcontroller*VC =[[Mfmailcomposeviewcontroller alloc] init];//Set Message subject[VC Setsubject:@"Conference"];//set up message content[VC Setmessagebody:@"Let's have a meeting this afternoon."Ishtml:no];//set up a recipient list[VC settorecipients:@[@"[email protected]"]];//set up a CC person list[VC setccrecipients:@[@"[email protected]"]];//set up a BCC list[VC setbccrecipients:@[@"[email protected]"]];//Add an attachment (a picture)UIImage *image = [UIImage imagenamed:@"Lufy.jpeg"]; NSData*data = uiimagejpegrepresentation (image,0.5); [VC addattachmentdata:data MimeType:@"IMAGE/JEPG"FileName:@"Lufy.jpeg"];//Set up proxyVc.mailcomposedelegate =Self ;//Display Controller[self PRESENTVIEWCONTROLLER:VC animated:yes completion:nil]; The proxy method callback after the message is sent, will automatically return to the original application after sending- (void) Mailcomposecontroller: (Mfmailcomposeviewcontroller *) controller didfinishwithresult: (mfmailcomposeresult) result Error: (Nserror *) error{//Close the Mail interface[Controller Dismissviewcontrolleranimated:yes Completion:nil]; if(Result = =mfmailcomposeresultcancelled) {NSLog (@"Cancel Send"); } Else if(Result = =mfmailcomposeresultsent) {NSLog (@"has been issued"); } Else{NSLog (@"Send failed"); }}

If you want to open some common files, such as HTML, TXT, PDF, PPT, etc., can be opened with UIWebView, just to tell the URL of the UIWebView file, as to open a remote shared resources, such as the HTTP protocol, You can also call the system's own Safari browser:

Nsurl *url = [Nsurl urlwithstring:@ "http://www.baidu.com"]; [[UIApplication sharedapplication] openurl:url];

3-ios-Small function (call, send text, send e-mail)

Related Article

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.