Inter-application jump, application jump

Source: Internet
Author: User

Inter-application jump, application jump
1. Configure URLSchemes

URLSchemes must be configured for the redirected application. Other applications are redirected to this application based on the URLSchemes of the application.

One APP can configure multiple URLSchemes, so that other apps can jump to this application no matter which URLSchemes they write.

Method 1: Configure Info. The Info. plist file is actually modified in essence.

Method 2: directly modify the Info. plist File

2. Configure the whitelist

The APP that initiates the jump directly performs the jump using openURL. iOS9 starts to determine whether the APP to which the jump is downloaded.

The canOpenURL method is used for determination. However, you must configure the whitelist to jump to the APP before using canOpenURL. Otherwise, NO is returned NO matter whether the user downloads or not.

Note: We generally use canOpenURL to determine and then redirect. However, you can directly use openURL for redirect. You do not need to configure the whitelist or canOpenURL for determination.

Configure the White List for the APP that is redirected(Apple requires a maximum of 50 white lists ):

Or use the code to add a whitelist:

 

1 <key>LSApplicationQueriesSchemes</key>2 <array>3       <string>toapp</string>4 </array>

 

3. redirected applications

AppDelegate implements the following methods:

1 // when the APP is opened by another APP, call 2 // app: 3 // url: the URL of the APP, that is, the URL used by other apps to open the APP, it may contain some parameters: 4 // options: 5 // return: whether to enable APP 6-(BOOL) application :( UIApplication *) app openURL :( NSURL *) url options :( NSDictionary <NSString *, id> *) options {7 8 NSString * urlString = url. absoluteString; 9 nsange xieyitouRange = [urlString rangeOfString: @ ": //"]; 10 nsange range = NSMakeRange (0, xieyitouRange. location + xieyitouRange. length); 11 12 // capture the parameter 13 NSString * queryString = [urlString substringFromIndex: range. location + range. length]; 14 UITabBarController * tabbarVC = (UITabBarController *) self. window. rootViewController; 15 16 // perform different operations 17 if ([queryString isEqualToString: @ "0"]) {18 tabbarVC based on different parameters passed by other apps. selectedIndex = 0; 19} 20 else {21 tabbarVC. selectedIndex = 1; 22} 23 24 // after the operation is completed, jump back to the APP25 dispatch_after (dispatch_time (DISPATCH_TIME_NOW, (int64_t) (3 * NSEC_PER_SEC) on the APP )), dispatch_get_main_queue (), ^ {26 [app openURL: [NSURL URLWithString: @ "fromapp: //"]; 27}); 28 29 return YES; 30}
4. Redirect Application Execution

Run the redirection code:

1-(IBAction) openURLRed :( id) sender {2 // openURL directly open other apps. toapp: // is the URLSchemes of the APP to be opened, the following 0 is parameter 3 [self. application openURL: [NSURL URLWithString: @ "toapp: // 0"]; 4} 5-(IBAction) openURLGreen :( id) sender {6 // openURL directly opens other apps. "toapp: //" is the URLSchemes of the APP to be opened. The following 0 is the parameter 7 [self. application openURL: [NSURL URLWithString: @ "toapp: // 1"]; 8} 9-(IBAction) canOpenURLRed :( id) sender {10 // use canOpenURL to determine whether the APP to be opened has been downloaded. toapp: // is the URLSchemes11 of the APP to be opened. // use this method, you must first set the whitelist (beginning with iOS9). Otherwise, NO12 if ([self. application canOpenURL: [NSURL URLWithString: @ "toapp: //"]) {13 [self. application openURL: [NSURL URLWithString: @ "toapp: // 0"]; 14} 15 else {16 NSLog (@ "You have not downloaded this APP "); 17} 18} 19-(IBAction) canOpenURLGreen :( id) sender {20 // use canOpenURL to determine whether the user has downloaded the APP to be opened: // "indicates the URLSchemes21 of the APP to be opened. // to use this method, you must first set the whitelist (beginning with iOS9, both return NO22 if ([self. application canOpenURL: [NSURL URLWithString: @ "toapp: //"]) {23 [self. application openURL: [NSURL URLWithString: @ "toapp: // 1"]; 24} 25 else {26 NSLog (@ "You have not downloaded this APP"); 27} 28}

 

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.