一五垮、Scheme
啟動App主要用到是自定義Scheme.
Scheme就類似確定了這個App所在的位置,程序就能找到它胯舷。
添加Scheme:
二、其他配置
iOS9之后需要在發(fā)起端添加白名單(即AppOne 喚起AppTwo在AppOne中添加)
LSApplicationQueriesSchemes
三黎泣、代碼
NSURL *appBUrl = [NSURL URLWithString:@"/*自定義的Scheme*/://"];if ([[UIApplication sharedApplication] canOpenURL:appBUrl]) {
// 3. 打開應(yīng)用程序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*)options completionHandler:(void (^ __nullable)(BOOL success))completion NS_AVAILABLE_IOS(10_0) NS_EXTENSION_UNAVAILABLE_IOS("");*/
四缤谎、具體調(diào)到某一個控制器
NSURL *appBUrl = [NSURL URLWithString:@"AppTwoScheme://starSecondContrller"];//添加后面的就可以區(qū)分了
//在AppTwo中 AppDelegate.m
- (BOOL)application:(UIApplication *)app openURL:(NSURL *)url options:(NSDictionary*)options
{
UINavigationController *rootNav = (UINavigationController *)self.window.rootViewController;NSLog(@"%@",url.absoluteString);//就能得到URLreturn YES;
}
轉(zhuǎn)載?http://www.th7.cn/Program/IOS/201711/1277338.shtml