Definition and use of IOS URL schemes

Source: Internet
Author: User

The role of the URL schemes on the iphone gives the application an additional application or safari can launch his method.

First, look at how to open other applications in your own application:
1. Open GoogleMap
Createyour query ...
Nsstring*searchquery = @ "1 Infinite Loop, Cupertino, CA95014";
Becareful to always URLs encode things like spaces and other symbolsthat aren ' t URL friendly
searchquery= [addresstextstringbyaddingpercentescapesusingencoding:nsutf8stringencoding];
Nowcreate the URL string ...
nsstring*urlstring = [nsstringstringwithformat:@ "http://maps.google.com/maps?q=%@", searchQuery];
An thefinal magic ... openurl!
[[UIApplication sharedapplication] openurl:[nsurlurlwithstring:urltext];

2. Open Mail
[[UIApplication sharedapplication] openurl:[nsurlurlwithstring:@ "Mailto://[email protected]"]

3. Turn on the phone
[[UIApplication sharedapplication] openurl:[nsurlurlwithstring:@ "tel://8004664411"];

4. Open SMS
[[UIApplication sharedapplication] openurl:[nsurlurlwithstring:@ "sms:55555"];

5. Open AppStore
Nsurl*appstoreurl = [nsurlurlwithstring:@] http://phobos.apple.com/WebObjects/MZStore.woa/wa/viewSoftware?id= 291586600&mt=8 "];
[[UIApplication sharedapplication] openurl:appstoreurl];

Second, let's look at how to get other applications to open our own programs
The principle is simple, first schemes is defined in the info.plist of your application, after the application is installed. The application can parse your info.plist, and if Cfbundleurltypes is detected, it will register the scheme with the system. If an application opens Safari via [[Uiapplicationsharedapplication]openurl:url] or enters a URL directly inside Safari. The system detects the URL, Then launch the appropriate application against the already registered scheme. The more common scheme is http,mailto,tel,sms. Of course you can define one yourself.
The application that is launched will invoke the

-(BOOL) Application: (uiapplication*) Applicationhandleopenurl: (Nsurl *) URL (4.2 previous iOS)
Or
-(BOOL) Application: (UIApplication *) Applicationopenurl: (nsurl *) URL sourceapplication: (nsstring*) sourceapplication annotation: (id) annotation (iOS after 4.2)

This function returns a bool value whose return value indicates whether the specified application is opened based on whether the contents of the URL are legitimate. When your application defines a scheme that can be opened by others, And you need to accept some parameters as the starting parameters. This is very dangerous. Therefore, the accepted URL needs to be checked, if it meets your requirements, then open the application, if not compliant, you can refuse to open!
To achieve such a feature, the steps are as follows:
(1) in Info.plist, add cfbundleurltypes, and then enter your own definition of scheme in the generated urlscheme
(2) Add Cfbundleurlname in Info.plist; he is an alias for your scheme. The following

OK, compile the upload simulator or the real machine, enter Schemes://url in Safari to test if you can start your application
The above example is Mosapp://balabala.

Definition and use of IOS URL schemes

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.