Start your app with a custom URL Scheme

Source: Internet
Author: User

Http://blog.csdn.net/ba_jie/article/details/6884818

The iPhone SDK can bind your app to a custom URL scheme. This URL scheme can be used to start your app from a browser or another app.

It is up to you to decide how to respond to the URL Scheme Application sent to you from another app: you can wake up your app or send some information to you.

It is very easy to register a URL scheme for your app. It is OK to define two key values in the info. plist file. As shown in:

    1. Add a key value called URL types.
    2. Add a URL identifier to item 1 in the format of Reverse Domain Name: COM. mycompany. MyApp.
    3. Add a URL scheme and define a value for it, any string. For example, MyApp.

After the definition ends, you can use the following mode to send a URL:

MyApp ://
MyApp: // some/path/here
MyApp ://? Foo = 1 & amp; bar = 2
MyApp: // some/path/here? Foo = 1 & amp; bar = 2

Then, your app's uiapplicationdelegate will receive a message. If you want to process the URL by yourself, you can reload the following method:

[Plain] View
Plaincopy

  1. -(Bool) Application :( uiapplication *) Application handleopenurl :( nsurl *) URL
  2. {
  3. // Do something with the URL here
  4. }

For example, save the uploaded URL locally:

[Plain] View
Plaincopy

  1. -(Bool) Application :( uiapplication *) Application handleopenurl :( nsurl *) URL
  2. {
  3. If (! URL)
  4. {
  5. Return no;
  6. }
  7. Nsstring * urlstring = [url absolutestring];
  8. [[Nsuserdefaults standarduserdefaults] setobject: urlstring forkey: @ "url"];
  9. [[Nsuserdefaults standarduserdefaults] synchronize];
  10. Return yes;
  11. }

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.