iOS 应用间跳转

@bingoogolapple 2016-06-14 04:11:07发表于 bingoogolapple/bingoogolapple.github.io iOS

编写需要被打开的应用 AppOne

配置 Info.plist 文件

image
或者
image

重写 AppDelegate 的 handleOpenURL 方法

- (BOOL)application:(UIApplication *)application handleOpenURL:(NSURL *)url {
    if (url) {
        [[[UIAlertView alloc] initWithTitle:nil message:[NSString stringWithFormat:@"absoluteString = %@\nscheme = %@\nquery = %@", url.absoluteString, url.scheme, url.query] delegate:self cancelButtonTitle:@"确定" otherButtonTitles:nil, nil] show];
    }
    return YES;
}

编写打开 AppOne 的应用 AppTwo

iOS9以后需要在 Info.plist 中配置 LSApplicationQueriesSchemes 需要被打开的应用的 Schemes

image

打开 AppOne

- (IBAction)openAppOne:(UIButton *)sender {
    NSURL * url = [NSURL URLWithString:@"appone://cn.bingoogolapple.appone?username=bingoogolapple&password=123456"];
    if ([[UIApplication sharedApplication] canOpenURL:url]) {
        NSLog(@"打开AppOne");
        [[UIApplication sharedApplication] openURL:url];
    }
}