iOS development: built-in URL schemes

Source: Internet
Author: User
Tags html page mail

In iOS apps, it's common to see apps jump directly to the App Store page with a click action, and start to wonder how this third party applies to iOS system application interactions. It was later found that the implementation of this communication in Apple's developer documentation is supported by default, as long as the Third-party application conforms to the specification, and the specification here refers to what we are going to briefly introduce--url schemes.

According to the rules, iOS supports several special URL schemes, Third-party local applications and Web applications running in Safari, through which schemes can be integrated with iOS system applications to provide users with a seamless user experience process. Some mobile phone iOS applications will display some phone number information, when the user clicks on these numbers, by using the appropriate URL, the application can open the phone application to dial call operation. This is a very fast way, eliminating the user to remember the number, and then the process of dialing.

1.URL Scheme Open Mode

Depending on the type of Third-party application, the way to open the iOS application is divided into two types
(1) Native app or the local application we often address, we can use the UIApplication OpenURL: method to System Application
(2) Web apps, or web apps that we often address, refer to Web applications that run in Safari browsers or embed local applications through UIWebView, and can be opened by clicking or operating on a long, open system application.
Of course, the prerequisite for a smooth open system application is that both are guaranteed to provide the specified URL scheme with the specification.

2.URL Scheme classification

iOS-supported URL schemes are grouped into the following categories

(1) Mail links (mail link)

The mail application is loaded through the Mailto protocol, provided the destination email address is available, the code is as follows
In an HTML page

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

In local applications

    1. if (![ [UIApplication sharedapplication]openurl:[nsurl urlwithstring:@ "mailto:frank@wwdcdemo.example.com"]]) {
    2. Uialertview *alert = [[Uialertview alloc]initwithtitle:@ "message:@" Cannot open program "Delegate:nil cancelbuttontitle:@" confirm " Otherbuttontitles:nil];
    3. [Alert show];
    4. }

You can also use the To,cc,bcc,subject,body field to specify the CC, BCC, subject, and message content of the message. Parameter values are processed by URL encoding.

    1. Mailto:foo@example.com?cc=bar@example.com&subject=greetings%20from%20cupertino!&body=wish%20you%20were %20here!

(2) Phone links (phone link)

The Tel protocol is used to start the phone application and call the specified number. Clicking on a number link on a Web page prompts a dialog box to prompt the user to dial, and start dialing after the user has allowed it. In a local application, opening a Tel protocol address directly dials the user prompt. In the following HTML page

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

In local applications

    1. if (![ [UIApplication sharedapplication]openurl:[nsurl urlwithstring:@ "tel:1-408-555-5555"]]) {
    2. Uialertview *alert = [[Uialertview alloc]initwithtitle:@ "message:@" Cannot open program "Delegate:nil cancelbuttontitle:@" confirm " Otherbuttontitles:nil];
    3. [Alert show];
    4. }

To prevent malicious numbers from redirecting or changing the call behavior and account number, the phone application supports most of the special characters of the Tel protocol. When the URL contains * or #, the phone application is not dialed. If your application is Tonguo user input or other unknown sources, any special characters in the URL will need to be encoded.           For local applications, you can use the NSString stringbyaddingpercentescapesusingencoding: method to encode. In addition, Safari in iOS defaults to performing number detection. However, if you have pages that contain numbers that can be detected as numbers but do not actually have a number, you can choose to turn off the current page's number detection behavior. Just add the following meta data to the page code

    1. <meta name = "format-detection" content = "Telephone=no" >

The next page will introduce you to text links (text link), itunes links (itunes link), youtube links (YouTube link)!

(3) Text links (text link)

Use the SMS protocol to load messages applications. The formal format of the URL is "sms:<phone>", where <phone> is optional to specify the number of the SMS message recipient.             The parameter value contains the number, "+", "-", ".". In an HTML page

    1. <a href= "SMS:" >launch Messages app</a>
    2. <a href= "sms:1-408-555-1212" >new SMS Message</a>

In local applications

    1. if (![ [UIApplication sharedapplication]openurl:[nsurl urlwithstring:@ "sms:1-408-555-1212"]]) {
    2. Uialertview *alert = [[Uialertview alloc]initwithtitle:@ "message:@" Cannot open program "Delegate:nil cancelbuttontitle:@" confirm " Otherbuttontitles:nil];
    3. [Alert show];
    4. }

(4) itunes links (itunes link)

The itunes link is used to link to content in the itunes store.              Through Apple's ITunes link maker we can easily query and get the application's link address. In an HTML page

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

In local applications

    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

The path cannot be/maps/*

Parameter cannot be q=*

Parameter cannot contain view=text or dirflag=r

(5) YouTube links (YouTube link)

The youtube link is used to load YouTube apps or Web sites linked to YouTube to play the specified video. Links to YouTube apps can play their videos.                Links start with HTTP, not YouTube. In an HTML page

    1. <a href= "Http://www.youtube.com/watch?v=xNsGNlDb6xY" >iPhone5</a>
    2. <a href= "Http://www.youtube.com/v/xNsGNlDb6xY" >iPhone5</a>

In the 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:@" Cannot open program "Delegate:nil cancelbuttontitle:@" confirm " 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.