应用之间跳转
在A项目中跳转到B项目
1、在B项目中添加一个URL Types
2、B项目:在AppDelegate.m中添加
- (BOOL)application:(UIApplication *)app openURL:(NSURL *)url options:(NSDictionary<NSString *,id> *)options{
NSString *urlStr = [url absoluteString];
if ([urlStr hasPrefix:@"ZhenYuDemo://"]) {
NSLog(@"TestAppDemo1 request params: %@", urlStr);
urlStr = [urlStr stringByReplacingOccurrencesOfString:@"ZhenYuDemo://" withString:@""];
NSArray *paramArray = [urlStr componentsSeparatedByString:@"&"];
NSLog(@"paramArray: %@", paramArray);
NSMutableDictionary *paramsDic = [[NSMutableDictionary alloc] initWithCapacity:0];
for (int i = 0; i < paramArray.count; i++) {
NSString *str = paramArray[i];
NSArray *keyArray = [str componentsSeparatedByString:@"="];
NSString *key = keyArray[0];
NSString *value = keyArray[1];
[paramsDic setObject:value forKey:key];
NSLog(@"key:%@ ==== value:%@", key, value);
}
}
return NO;
}
3、在A项目的info.plist中添加LSApplicationQueriesSchemes —>ZhenYuDemo(B项目中添加URL Types的URL Schemes)
4、在A项目需要跳转B项目的事件中添加
- (void)APCheckIfAppInstalled2:(NSString *)urlSchemes{
if ([[UIApplication sharedApplication] canOpenURL:[NSURL URLWithString:urlSchemes]]){
NSString *paramStr = [NSString stringWithFormat:@"ZhenYuDemo://username=%@&age=%@&address=%@", @"test123", @"100", @"深圳市"];
NSURL *url = [NSURL URLWithString:[paramStr stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];
[[UIApplication sharedApplication] openURL:url];
}else{
NSLog(@" 未安装软件");
}
}
//若设备中安装了ZhenYuDemo项目,则跳转;若未安装,则不跳转
[self APCheckIfAppInstalled2:@"ZhenYuDemo://"];
不清楚参考:http://www.cnblogs.com/xiu619544553/p/5889452.html