A、B都是自己的项目
跳转方向:A ----> B
一、设置B
1.1 在B中设置 URL Schemes (也可在plist文件中设置)
targets --> Info --> URL Types --> URL Schemes
1.2 在AppDelegate.m
中获取A传过来的值
- (BOOL)application:(UIApplication *)application handleOpenURL:(NSURL *)url{
if ([[url scheme] containsString:@"iOSMark"]) {
NSLog(@"url == %@", url);//url的全部(iOSMark://11,22)
NSLog(@"url scheme == %@", [url scheme]);//冒号前部分(iOSMark)
NSLog(@"url resourceSpecifier == %@", [url resourceSpecifier]);//冒号后部分(//11,22)
NSLog(@"url.host == %@", url.host);//(11,22)若有UTF-8编码,在此会显示汉字
}
return YES;
}
贴图:
二、设置A
2.1设置白名单
targets --> Info --> Custom iOS Target Properties -->LSApplicationQueriesSchemes
贴图:
2.2 代码
NSString *urlStr = [NSString stringWithFormat:@"iOSMark:"];
urlStr = [urlStr stringByAppendingString:@"11,22"];//添加参数
//urlStr = [urlStr stringByAppendingString:@"11,22,王平波"];//有汉字,转UTF-8
//urlStr = [urlStr stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];//汉字转UTF-8
NSURL *url = [NSURL URLWithString:urlStr];
if ([[UIApplication sharedApplication] canOpenURL:url]) {
[[UIApplication sharedApplication] openURL:url];
} else {
//如果不能打开,跳到appStore下载页面
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"https://itunes.apple.com/cn/app/powermark-wang-shang-yue-juan/id989100643?mt=8"]];
}