iOS App间跳转

A应用跳转到B应用
如下图在B应用项目中设置了URL Schemes, UrlTyps 是一个数组,可以设置多个Schemes,具体值可以随便写

image.png

B应用在info.plist - LSApplicationQueriesSchemes 中添加A应用的Schemes
一定要添加否则[UIApplication sharedApplication] canOpenURL:] 是否

image.png
 //通过以下方式跳转
    NSURL *Url = [NSURL URLWithString:@"hhSimple://com.hhAPP"];
//    NSURL *Url = [NSURL URLWithString:@"HHChat://com.hhAPP"];
    if ([[UIApplication sharedApplication] canOpenURL:Url]) {
        [[UIApplication sharedApplication] openURL:Url options:@{} completionHandler:^(BOOL success) {
            if (success) {
                
            }
        }];
    } else {
        UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"提示" message:@"未安装皖税通" preferredStyle:UIAlertControllerStyleAlert];
        UIAlertAction *sure = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
        }];
        [alert addAction:sure];
        dispatch_async(dispatch_get_main_queue(), ^{
            [self presentViewController:alert animated:YES completion:nil];
        });
    }

在appDelegate 中,通过此方法判断app从那个应用跳转过来

- (BOOL)application:(UIApplication *)app openURL:(NSURL *)url options:(NSDictionary *)options {
    if ([url.absoluteString containsString:@"hhSimple"]) {
        //此处可判断app从哪里跳转过来
    }
    
    return YES;
}

你可能感兴趣的:(iOS App间跳转)