Cat learning iOS () commonly used small functions such as making a phone call, opening a website, sending an email, and sending a text message to open other applications ., Ios email
CAT/CAT sharing, must be excellent
For Original Articles, please reprint them. Reprinted Please note: Yan Nai-yu's blog
Http://blog.csdn.net/u013357243? Viewmode = contents
Introduction
Many of the minor functions in iOS are very simple, just a few lines of code, such as making a call, opening a website, sending an email, sending a text message, and opening other applications.
Call method 1
The simplest and most direct method: Jump directly to the dialing Interface
NSURL *url = [NSURL URLWithString:@"tel://10010"];[[UIApplication sharedApplication] openURL:url];
Disadvantages
After the phone is called, it will not automatically return to the original application and will stay on the call record page.
Method 2
Before dialing, a dialog box is displayed asking if the user is dialing. After dialing, the user can automatically return to the original application.
NSURL *url = [NSURL URLWithString:@"telprompt://10010"];[[UIApplication sharedApplication] openURL:url];
Disadvantages
Because it is a private API, it may not pass the review (don't think it can be a bad thing, it will be nice to yourself)
Method 3
Create a UIWebView to load the URL, and then return to the original application automatically after dialing.
if (_webView == nil) { _webView = [[UIWebView alloc] initWithFrame:CGRectZero];}[_webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:@"tel://10010"]]];
Note that this webView must not be added to the interface, otherwise it will block other interfaces.
Method 1
Directly jump to the text message interface, but cannot specify the text message content, and cannot automatically return to the original application
NSURL *url = [NSURL URLWithString:@"sms://10010"];[[UIApplication sharedApplication] openURL:url];
Method 2
If you want to specify the text message content, you must use the MessageUI framework.
Contains the primary header file
Import
MFMessageComposeViewController * vc = [[MFMessageComposeViewController alloc] init]; // sets the text message content vc. body = @ "have you eaten? "; // Set the recipient list vc. recipients = @ [@ "10010", @ "02010010"]; // sets the proxy vc. messageComposeDelegate = self; // display controller [self presentViewController: vc animated: YES completion: nil]; proxy method called when the text message interface is closed, after sending the message, it will automatically return to the original application-(void) messageComposeViewController :( MFMessageComposeViewController *) controller didFinishWithResult :( MessageComposeResult) result {// close the text message interface [controller complete: YES completion: N if (result = MessageComposeResultCancelled) {NSLog (@ "cancel sending");} else if (result = MessageComposeResultSent) {NSLog (@ "sent ");} else {NSLog (@ "failed to send ");}}
Mail method 1
The built-in email client does not automatically return to the original application after the mail is sent.
NSURL *url = [NSURL URLWithString:@"mailto://10010@qq.com"];[[UIApplication sharedApplication] openURL:url];
Method 2
Similar to the 2nd method of text message, the Controller class name is MFMailComposeViewController.
Assume that the content of the sent email is shown in the right figure.
The proxy method callback after the email is sent. It will automatically return to the original application after the email is sent.
-(Void) mailComposeController :( MFMailComposeViewController *) controller didFinishWithResult :( MFMailComposeResult) result error :( NSError *) error {// close the email interface [controller condition: YES completion: nil]; if (result = MFMailComposeResultCancelled) {NSLog (@ "cancel sending");} else if (result = MFMailComposeResultSent) {NSLog (@ "sent ");} else {NSLog (@ "failed to send ");}}
Open other common files
You can use UIWebView to open common files, such as html, txt, PDF, and PPT.
You only need to tell the URL of the UIWebView file.
To open a remote shared resource, such as the http protocol, you can also call the Safari browser that comes with the system:
NSURL *url = [NSURL URLWithString:@”http://www.baidu.com"];[[UIApplication sharedApplication] openURL:url];
Inter-application jump
Sometimes, you need to open other applications in this application, for example, jump from application A to application B.
First, application B must have its own URL address (configured in Info. plist)
The URL of application B is mm: // www.nycat.com.
Use UIApplication in application A to complete the redirection.
NSURL * url = [NSURL URLWithString: @ "mm: // www.nycat.com"];
[[UIApplication sharedApplication] openURL: url];