Cat learn iOS (45) commonly used small features such as phone calls, open URLs, e-mail, text messages to open other applications.

Source: Internet
Author: User

Cat Share, must boutique

Original articles, welcome reprint. Reprint Please specify: Sanayu's Blog
Address: http://blog.csdn.net/u013357243?viewmode=contents

Brief introduction

Many of the small features in iOS are simple, with a few lines of code, such as calling, opening URLs, sending emails, texting, opening other apps, and more.

How to call 1

The simplest and most straightforward way: jump directly to the dial-up interface

NSURL *url = [NSURL URLWithString:@"tel://10010"];[[UIApplication sharedApplication] openURL:url];

Disadvantages
After the call, will not automatically return to the original application, directly in the Call log interface

Method 2

Before dialing, the box asks the user whether to dial or not and automatically returns to the original application after dialing out.

NSURL *url = [NSURL URLWithString:@"telprompt://10010"];[[UIApplication sharedApplication] openURL:url];

Disadvantages
Because it is a private API, it may not be audited (don't think you can do bad things, you shuangshuang yourself)

Method 3

Create a UIWebView to load the URL and automatically go back to the original app when you're finished dialing

ifnil) {    [[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

Texting Method 1

Jump directly to the text messaging interface, but cannot specify the text message content, and can not automatically return to the original application

NSURL *url = [NSURL URLWithString:@"sms://10010"];[[UIApplication sharedApplication] openURL:url];

Method 2

If you want to specify a text message, you have to use the MESSAGEUI framework
Include primary header file

Import
Mfmessagecomposeviewcontroller *VC = [[Mfmessagecomposeviewcontroller alloc] init];//Set SMS contentVc. Body= @"Have you eaten yet?" ";//Set recipient listVc. Recipients= @[@"10010", @"02010010"];//Set up proxyVc. Messagecomposedelegate= Self;//Display Controller[ SelfPRESENTVIEWCONTROLLER:VC Animated:YESCompletion:Nil] Agent method, when the text message 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:YESCompletion:Nil];if(Result = = messagecomposeresultcancelled) {NSLog(@"Cancel Send"); }Else if(Result = = Messagecomposeresultsent) {NSLog(@"already issued."); }Else{NSLog(@"Send Failed"); }}
Outgoing Mail Method 1

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

NSURL *url = [NSURL URLWithString:@"mailto://[email protected]"];[[UIApplication sharedApplication] openURL:url];

Method 2

The 2nd method of texting is similar, except that the controller class name is: Mfmailcomposeviewcontroller
Assuming that the message is sent as shown in the image on the right, the code implementation looks at the notes

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 Mail Interface  [controller Dismissviewcontrolleranimated:yes  completion:nil    ]; if  (Result = = mfmailcomposeresultcancelled)    {nslog  (@ "Cancel Send" );        } else  if  (result = = Mfmailcomposeresultsent) { nslog     (@ "already issued" ); } else  {nslog  (@); }}
Open Other Common Files

If you want to open some common files, such as HTML, TXT, PDF, PPT, etc., you can use UIWebView open
Just tell the URL of the UIWebView file to
As for opening a remote shared resource, 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];
Inter-app Jump

Sometimes it is necessary to open other applications in this application, such as jumping from A to B application

First, the B application has its own URL address (configured in info.plist)


b The URL address of the app is: mm://www.nycat.com

Then use UIApplication in a application to complete the jump
Nsurl *url = [Nsurl urlwithstring:@ "mm://www.nycat.com"];
[[UIApplication sharedapplication] openurl:url];

Cat learn iOS (45) commonly used small features such as phone calls, open URLs, e-mail, text messages to open other applications.

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.