一、Scheme
启动App主要用到是自定义Scheme.
Scheme就类似确定了这个App所在的位置,程序就能找到它。
添加Scheme:
二、其他配置
iOS9之后需要在发起端添加白名单(即AppOne 唤起AppTwo在AppOne中添加)
LSApplicationQueriesSchemes
三、代码
NSURL *appBUrl = [NSURL URLWithString:@"/*自定义的Scheme*/://"];
if ([[UIApplication sharedApplication] canOpenURL:appBUrl]) {
// 3. 打开应用程序App-B
[[UIApplication sharedApplication] openURL:appBUrl
options:@{}//传空即可
completionHandler:^(BOOL success) {
NSLog(@"打开成功");
}];
} else {
NSLog(@"没有安装");
}
/*iOS10之前用的是 [[UIApplication sharedApplication] openURL:appBUrl];
不过被弃用了
- (BOOL)canOpenURL:(NSURL *)url NS_AVAILABLE_IOS(3_0);
// Options are specified in the section below for openURL options. An empty options dictionary will result in the same 这里也说的很清楚了字典传空就和以前的方法一样了。
// behavior as the older openURL call, aside from the fact that this is asynchronous and calls the completion handler rather
// than returning a result.
// The completion handler is called on the main queue.
- (void)openURL:(NSURL*)url options:(NSDictionary<NSString *, id> *)options completionHandler:(void (^ __nullable)(BOOL success))completion NS_AVAILABLE_IOS(10_0) NS_EXTENSION_UNAVAILABLE_IOS("");
*/
四、具体调到某一个控制器
NSURL *appBUrl = [NSURL URLWithString:@"AppTwoScheme://starSecondContrller"];//添加后面的就可以区分了
//在AppTwo中 AppDelegate.m
- (BOOL)application:(UIApplication *)app openURL:(NSURL *)url options:(NSDictionary<UIApplicationOpenURLOptionsKey,id> *)options
{
UINavigationController *rootNav = (UINavigationController *)self.window.rootViewController;
NSLog(@"%@",url.absoluteString);//就能得到URL
return YES;
}