實(shí)現(xiàn)兩個(gè) app 的跳轉(zhuǎn)
這里我創(chuàng)建了兩個(gè) demo. 名字叫 A 和 B . 現(xiàn)在要想從 A 跳轉(zhuǎn)到 B 實(shí)現(xiàn)流程
第一步 我們?nèi)サ?B app 的項(xiàng)目中做如下操作
圖片.png
操作完了之后 在到 B 項(xiàng)目的appdelegate 的. m 文件中實(shí)現(xiàn)以下代理
方法
圖片.png
第一步到這里完成了,此時(shí)我們需要到 A 項(xiàng)目中去配置了
如果你的 ios 系統(tǒng)高于9.0 info.plist文件中增加一個(gè)LSApplicationQueriesSchemes字段,把它設(shè)置為數(shù)組類型弧蝇,并配置需要跳轉(zhuǎn)的協(xié)議名單.如下圖
圖片.png
設(shè)置完成之后 我們就可以進(jìn)行跳轉(zhuǎn)代碼了
- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{
NSString *appString = @"testB://這個(gè)后面可以拼接你需要傳遞到 B app 的參數(shù)";
// 接下來就是我做跳轉(zhuǎn)遇到的一個(gè)坑
//就是要對(duì) appString 進(jìn)行 utf8編碼. 不然可能會(huì)出現(xiàn) url 為 nil 的情況! 當(dāng)然你從傳遞的參數(shù)沒有特殊字符和中文也可以不編碼
appString = [appString stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet URLQueryAllowedCharacterSet]];
NSURL *url = [NSURL URLWithString:appString];
if ([[UIApplication sharedApplication] canOpenURL:url]) {
if ([[UIDevice currentDevice].systemVersion floatValue] >= 10.0){
// ios10 用這個(gè)
[[UIApplication sharedApplication] openURL:url options:@{} completionHandler:^(BOOL success) {
}];
}else{
[[UIApplication sharedApplication]openURL:url];
}
}else{
NSLog(@"沒有安裝應(yīng)用");
}
}