1、新建两个项目:AppOne,AppTwo;
2、分别在其属性列表中添加如下:
AppOne:
AppTwo:
AppOne的 viewController.m 中添加代码:
- (void) touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
NSURL *url = [NSURLURLWithString:@"AppTwo:"];
if ([[UIApplicationsharedApplication] canOpenURL:url]) // 判断设备是否安装了AppTwo
{
NSLog(@"canOpenURL");
[[UIApplication sharedApplication] openURL:url]; // 打开AppTwo应用, 如果你想携带参数: NSURL *url = [NSURLURLWithString:@"AppTwo://你想携带的代数"];
} else
{
NSLog(@"can not OpenURL");
}
}
AppTwo的 viewController.m 中添加代码:
// AppDelegate里面接收url
- (BOOL)application:(UIApplication *)app openURL:(NSURL *)url options:(NSDictionary<UIApplicationOpenURLOptionsKey, id> *)options
{
NSLog(@"--%@", url);
return YES;
}
- (void) touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
NSLog(@"touchesBegan");
NSURL *url = [NSURLURLWithString:@"AppOne:"];
if ([[UIApplicationsharedApplication] canOpenURL:url])
{
NSLog(@"canOpenURL");
[[UIApplication sharedApplication] openURL:url];
} else
{
NSLog(@"can not OpenURL");
}
}