第一个APP
添加标记
添加白名单
设置跳转url和返回标记
//跳转到YourApp
- (IBAction)gotoYourApp:(UIButton *)sender {
NSURL * url = [NSURL URLWithString:@"YourApp://aaa?backscheme=MyApp"];
UIApplication * app = [UIApplication sharedApplication];
if ([app canOpenURL:url]) {
[app openURL:url];
} else {
NSLog(@"打开失败");
}
}
跳转到其他APP的指定页面
- (IBAction)gotoYourAppP2:(UIButton *)sender {
NSURL * url = [NSURL URLWithString:@"YourApp://bbb?backscheme=MyApp"];
UIApplication * app = [UIApplication sharedApplication];
if ([app canOpenURL:url]) {
[app openURL:url];
}
}
第二个APP
设置标记和白名单
在AppDelegate中通过传入参数跳转到指定页面
/** 拦截页面跳转的传参 */
- (BOOL)application:(UIApplication *)app openURL:(NSURL *)url options:(NSDictionary<NSString *,id> *)options {
//获取导航控制器
UINavigationController * navi = (UINavigationController *)self.window.rootViewController;
ViewController * view = (ViewController *)navi.topViewController;
NSString * urlStr = url.absoluteString;
NSRange range = [urlStr rangeOfString:@"backscheme="];
//获取返回的Scheme
if (range.length>0) {
//由range的长度和位置,获得需要截取的位置
NSInteger fromIndex = range.length + range.location;
NSString * backSch = [urlStr substringFromIndex:fromIndex];
view.backScheme = backSch;
}
if ([urlStr hasPrefix:@"YourApp://bbb"]) {
[view performSegueWithIdentifier:@"YourAppP2" sender:nil];
}
return YES;
}