IOS development: built-in URL schemes

Source: Internet
Author: User

IOS development: built-in URL schemes

In IOS applications, you can often see some applications jump directly to the App Store page through a click action. It is strange how such a third-party applies to interaction between IOS system applications. Later, we found that the implementation of such communication is supported by default in Apple's developer documentation, as long as third-party applications comply with the specifications, the specification here refers to the URL Schemes, which we will briefly introduce.

According to regulations, IOS supports several special URL schemes, third-party local applications and Web applications running in Safari. These URL schemes can be integrated with IOS system applications, in order to provide users with a seamless user experience process. Some mobile phone numbers are displayed in IOS apps. When you click these numbers, you can use the specified URL, the Application can open the Phone Application of the mobile Phone to perform dial-up call operations. This is a fast way to save the user's need to remember the number, and then dial the process.

1. URL scheme open mode

Based on the types of third-party applications, there are two ways to open IOS applications:
(1) Native apps or local applications that we often call can be applied through the openURL of UIApplication: method.
(2) A Web App, or a Web application that we often call, refers to Web applications that run in Safari or embed local applications in UIWebView, you can click or press it to open the system application.
Of course, the premise of successfully opening the system application is that both of them must ensure that the specified URL scheme is provided.

2. URL Scheme Classification

The URL Schemes supported by IOS is divided into the following types:

(1) Mail Links (email link)

Use the mailto protocol to load the Mail application. You only need to provide the target email address. The Code is as follows:
HTML page

 
  1. <A href = "mailto: frank@wwdcdemo.example.com"> John Frank </a>

Local Application

 
  1. If (! [[UIApplication sharedApplication] openURL: [NSURL URLWithString: @ "mailto: frank@wwdcdemo.example.com"]) {
  2. UIAlertView * alert = [[UIAlertView alloc] initWithTitle: @ "message: @" unable to open the program "delegate: nil cancelButtonTitle: @" OK "otherButtonTitles: nil];
  3. [Alert show];
  4. }

You can also use the to, cc, bcc, subject, and body fields to specify the cc, bcc, topic, and message content of an email. The parameter values must be URL encoded.

 
  1. Mailto: foo@example.com? Cc = bar@example.com & subject = Greetings % 20 from % 20 Cupertino! & Body = Wish % 20you % 20 were % 20 here!

(2) Phone links)

The tel protocol is used to start the Phone application and call the specified number. Click a number link on the webpage to bring up a dialog box prompting you whether to dial the number and start dialing after the user permits it. In a local application, opening a tel Protocol address will directly dial up and prompt the user. In the following HTMl page

 
  1. <A href = "tel: 1-408-555-5555"> 1-408-555-5555 </a>

Local Application

 
  1. If (! [[UIApplication sharedApplication] openURL: [NSURL URLWithString: @ "tel: 1-408-555-5555"]) {
  2. UIAlertView * alert = [[UIAlertView alloc] initWithTitle: @ "message: @" unable to open the program "delegate: nil cancelButtonTitle: @" OK "otherButtonTitles: nil];
  3. [Alert show];
  4. }

To prevent malicious number redirection or change calls and accounts, the Phone app supports most of the special characters in the tel protocol. When the URL contains * or #, the Phone application does not dial. If your application is obtained from tonguo user input or other unknown sources, any special characters in the URL must be encoded. For local applications, the stringByAddingPercentEscapesUsingEncoding method of NSString can be used for encoding. In addition, safari in IOS performs number detection by default. However, if your page contains a number that can be detected as a number but does not actually mean a number, you can disable the number detection behavior on the current page. You only need to add the following metadata to the page code.

 
  1. <Meta name = "format-detection" content = "telephone = no">

The next page will introduce you to Text links, iTunes links, and Youtube links )!

 

(3) Text links)

Use the sms protocol to load the Messages application. The official format of this URL is "sms: <phone>", where <phone> is optional and used to specify the number of the sms message recipient. The parameter value contains numbers, "+ ","-",".". HTML page

 
  1. <A href = "sms:"> Launch Messages App </a>
  2. <A href = "sms: 1-408-555-1212"> New SMS Message </a>

Local Application

 
  1. If (! [[UIApplication sharedApplication] openURL: [NSURL URLWithString: @ "sms: 1-408-555-1212"]) {
  2. UIAlertView * alert = [[UIAlertView alloc] initWithTitle: @ "message: @" unable to open the program "delegate: nil cancelButtonTitle: @" OK "otherButtonTitles: nil];
  3. [Alert show];
  4. }

(4) iTunes links (iTunes link)

The iTunes link is used to link to the content in the iTunes Store. Through Apple's iTunes Link Maker, we can easily query and obtain the application's Link address. HTML page

 
  1. <A href = "https://itunes.apple.com/cn/app/numbers/id361304891? Mt = 8 "> Numbers </a>

Local Application

 
  1. [[UIApplication sharedApplication] openURL: [NSURL URLWithString: @ "http://maps.apple.com /? Q = cupertino "];

The correct map link format rules are as follows:

The domain name must be maps.apple.com.

Path cannot be/maps /*

The parameter cannot be q = *

The parameter cannot contain view = text or dirflag = r.

(5) Youtube links (Youtube link)

A Youtube link is used to load a YouTube app or a website with a link value of YouTube to play a specified video. Apps linked to Youtube can play their videos. The link starts with http, not youtube. HTML page

 
  1. <A href = "http://www.youtube.com/watch? V = xNsGNlDb6xY "> iPhone5 </a>
  2. <A href = "http://www.youtube.com/v/xNsGNlDb6xY"> iPhone 5 </a>

Local Application

 
  1. // Or http://www.youtube.com/v/xNsGNlDb6xY
  2. If (! [[UIApplication sharedApplication] openURL: [NSURL URLWithString: @ "http://www.youtube.com/watch? V = xNsGNlDb6xY "]) {
  3. UIAlertView * alert = [[UIAlertView alloc] initWithTitle: @ "message: @" unable to open the program "delegate: nil cancelButtonTitle: @" OK "otherButtonTitles: nil];
  4. [Alert show];
  5. }

 

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.