iOS opens other apps, and is opened by other apps

Source: Internet
Author: User

1. Open Other applications

Appurlstr = "cwork://app_id?title=xxx&content=xxx"

[[uiapplication sharedapplication] openURL: [nsurl urlwithstring: APPURLSTR]];

    • Requires the other app to be configured in Info.pist:

This allows the other application to be tuned.

2. Opened by other applications

(1) as shown, need to configure themselves in the Info.plist, others fall themselves, where identifer no use, mainly the URL schemes, it will be used to splice the URL of the transfer: such as: Cwork://xx-id?parame1 = "1" & Parame2= "2"

A, when the program is already running, it will arouse the agent in Appdelegate:

#define CWORKURLSCHEML      @ "cwork://"-(BOOL) Application: (UIApplication *) application Handleopenurl: (Nsurl *) url{    if (!url) {        return NO;    }        NSString *urlstring = [url absolutestring];    Listen for who is tuned    if ([urlstring rangeofstring:cworkurlscheml].length > 0) {    }    return YES;}

B. When the program is first started:

-(BOOL) Application: (UIApplication *) application didfinishlaunchingwithoptions: (Nsdictionary *) launchOptions {      Nsurl *alaunchoptionsurl = [Launchoptions Objectforkey:uiapplicationlaunchoptionsurlkey];    Wake-up monitoring by other application, parsing    if ([alaunchoptionsurl.absolutestring hasprefix:cworkurlscheml]) {    }return YES;}

  

(2) then the URL with parameters, you can parse the URL to "?" As a delimiter, parse the arguments on both sides

+ (Nsdictionary *) Urlpropertyvalue: (NSString *) aurlstr{    nsarray *alist = [Aurlstr componentsseparatedbystring:@ "?"];    if (Alist.count < 2) {        return nil;    }    Nsmutabledictionary *adict = [nsmutabledictionary dictionary];    NSString *rootpath = [alist objectatindex:0];    [Adict setobject:rootpath forkey:@ "RootPath"];    NSString *avaluestr = [alist objectatindex:1];    Nsarray *alist1 = [avaluestr componentsseparatedbystring:@ "&"];    For (NSString *astr in aList1) {        Nsarray *l = [aStr componentsseparatedbystring:@ "="];        if (L.count = = 2) {            nsstring *k = [L objectatindex:0];            NSString *v = [L objectatindex:1];            [Adict setobject:v forkey:k];        }    return adict;}

  

iOS opens other apps, and is opened by other apps

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.