IOS phone, text message, and so on
The simplest and most direct method: Jump directly to the dialing Interface
1
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.
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 be approved
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.
Text message-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];
Text message-method 2
If you want to specify the text message content, you must use the MessageUI framework.
Contains the primary header file
# Import
Display the SMS Controller
MFMessageComposeViewController * vc = [[MFMessageComposeViewController alloc] init];
// Set the text message content
Vc. body = @ "have you eaten? ";
// Set the recipient list
Vc. recipients = @ [@ "10010", @ "02010010"];
// Set proxy
Vc. messageComposeDelegate = self;
// Display controller
[Self presentViewController: vc animated: YES completion: nil];
Proxy method. It is called when the text message interface is closed. It is automatically returned to the original application after being sent.
-(Void) messageComposeViewController :( MFMessageComposeViewController *) controller didFinishWithResult :( MessageComposeResult) result
{
// Close the text message interface
[Controller dismissViewControllerAnimated: YES completion: nil];
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];
Mail-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 dismissViewControllerAnimated: 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];
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 mj: // ios.itcast.cn.
Use UIApplication in application A to complete the redirection.
NSURL * url = [NSURL URLWithString: @ "mj: // ios.itcast.cn"];
[[UIApplication sharedApplication] openURL: url];
Application rating
To improve the user experience of the application, users are often invited to rate the application.
The app rating is nothing more than jump to the AppStore to show your app, and then the user will write the comment
How to jump to the AppStore and display your own applications
Method 1
NSString * appid = @" 444934666 ";
NSString * str = [NSString stringWithFormat:
@ "Itms-apps: // ax.itunes.apple.com/WebObjects/MZStore.woa/wa/viewContentsUserReviews? Type = Purple + Software & id = % @ ", appid];
[[UIApplication sharedApplication] openURL: [NSURL URLWithString: str];
Method 2
NSString * str = [NSString stringWithFormat:
@ "Itms-apps: // itunes.apple.com/cn/app/id @? Mt = 8 ", appid];
[[UIApplication sharedApplication] openURL: [NSURL URLWithString: str];