##### Web wake-up app: You can wake up an app at URL Schemes. What exactly is Access to Access to access to access to access to access to access to access to access to access to access to access to access to access to access to access to access to access to access to access. Of course, this flag may not be unique, as one can define one app’s Access schemes as myApp, and another can define another app’s access schemes as myApp.

Create a new personal app: TARGETS->info->URL Types-> click on “+” to define URL Schemes openApp. At this point, if only the web wakes up the application, the job is done.

If you view it in the info.plist file of the project, it is:

URL types->item0->URL Schemes->item0

AppDelegate.m:

// // appdelegate. m // OpenApp // // Created by MAC on 17/4/28. // Copyright © 2017 CAI. All rights reserved#import "AppDelegate.h"
#import "ViewController.h"

@interface AppDelegate ()

@end

@implementation AppDelegate


- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    // Override point for customization after application launch.
    
    self.window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];
    
    ViewController *vc = [[ViewController alloc] init];
    UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:vc];
    self.window.rootViewController = nav;
    
    [self.window makeKeyAndVisible];
    
    returnYES; } //iOS8 and below this - (BOOL) Application (UIApplication *) Application openURL (NSURL *) URLsourceApplication:(NSString *)sourceApplication annotation:(id)annotation {
    
    returnYES; } //iOS9 and above this - (BOOL) Application (UIApplication *)app openURL (NSURL *) URL options:(NSDictionary<UIApplicationOpenURLOptionsKey,id> *)options { NSLog(@"--url: %@", url);
    
    returnYES; } @end Output: 2017-04-28 14:39:31.684442+0800 OpenApp[14303:3806016] -- URL: OpenApp ://Copy the code

We can add parameters to URL Schemes: openApp, such as: openApp://www.baidu.com

2017-04-28 14:44:21.115314+0800 OpenApp[14303:3806016] -- URL: OpenApp ://www.baidu.comCopy the code

Then take the parameter and do the corresponding operation.

Effect:


##### One app wakes up another app:

Two new personal applications are respectively OpenAppA and OpenAppB, and the former awakens the latter as an example. Two other apps have been launched: Didi Enterprise and Didi Personal. (Didi Enterprise edition is not installed on my phone, but Didi Personal Edition and the new OpenAppB app are installed on my phone.)

Let’s start with the OpenAppA application configuration: in its info.plist:

PS: Didi Enterprise URL Schemes Didies and Didi Personal URL Schemes Onetravel. I’m defining URL Schemes for OpenAppB as OpenAppB, which can be customized.

ViewController.m:

// // viewController.m // OpenAppA // // Created by MAC on 17/4/28. // Copyright © 2017 CAI. All rights reserved#import "ViewController.h"

@interface ViewController ()

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
    
    self.title = @"OpenAppA";
    
    self.view.backgroundColor = [UIColor orangeColor];
    
    [self testPushDidi];
    
}

#pragma mark -create UI
- (void)testPushDidi
{
    UIButton *btn1 = [UIButton buttonWithType:UIButtonTypeCustom];
    [btn1 setTitle:@Didi Enterprise Edition forState:UIControlStateNormal];
    btn1.frame = CGRectMake(10, 100, 100, 50);
    btn1.backgroundColor = [UIColor purpleColor];
    [btn1 addTarget:self action:@selector(btn1Action) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:btn1];
    
    
    UIButton *btn2 = [UIButton buttonWithType:UIButtonTypeCustom];
    [btn2 setTitle:@Didi Personal Edition forState:UIControlStateNormal];
    btn2.frame = CGRectMake(10, 200, 100, 50);
    btn2.backgroundColor = [UIColor purpleColor];
    [btn2 addTarget:self action:@selector(btn2Action) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:btn2];
    
    
    UIButton *btn3 = [UIButton buttonWithType:UIButtonTypeCustom];
    [btn3 setTitle:@"openAppB" forState:UIControlStateNormal];
    btn3.frame = CGRectMake(10, 300, 100, 50);
    btn3.backgroundColor = [UIColor purpleColor];
    [btn3 addTarget:self action:@selector(btn3Action) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:btn3];
}

- (void)btn1Action
{
    NSString *str = @"didies://";
    NSURL *url = [NSURL URLWithString:str];
    if ([[UIApplication sharedApplication] canOpenURL:url]) {
        
        [[UIApplication sharedApplication] openURL:url];
    }else {
        NSLog(@"Can Not -- Didi Enterprise Edition");
        [[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"https://itunes.apple.com/us/app/di-di-qi-ye-ban-mei-hao-shang/id1061542715?mt=8"]];
    }
}

- (void)btn2Action
{
    NSString *str = @"onetravel://";
    NSURL *url = [NSURL URLWithString:str];
    if ([[UIApplication sharedApplication] canOpenURL:url]) {
        
        [[UIApplication sharedApplication] openURL:url];
    }else {
        NSLog(@"Can Not -- Didi Personal Edition");
        [[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"https://itunes.apple.com/cn/app/di-di-da-che-da-che-shen-qi/id554499054?mt=8"]];
    }
}

- (void)btn3Action
{
    NSString *str = @"openAppB://";
    NSURL *url = [NSURL URLWithString:str];
    if ([[UIApplication sharedApplication] canOpenURL:url]) {
        
        [[UIApplication sharedApplication] openURL:url];
    }else {
        NSLog(@"can not");
    }
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}


@end
Copy the code

Graph:

OpenAPPB application:

You just need to configure URL Schemes openAppB.

Effect:

  • Click the Didi Enterprise edition button

Because didi Enterprise edition is not installed, else jumps to the Download page of Didi Enterprise Edition in App Store;

Output:

2017-04-28 16:04:36.825447+0800 OpenAppA[14375:3822064] -canOpenURL: failed for URL: "didies://" - error: "The operation couldn't be completed. (OSStatus error-10814.)"825635+0800 OpenAppA[14375:3822064] Can Not -- Didi Enterprise EditionCopy the code
  • Click the Didi Personal edition button

If you have installed didi Personal edition locally, open the app.

  • Click the openAppB button

The effect is consistent with opening didi personal version