UIApplication sharedApplication] openURL:[NSURL URLWithString:@"ProductTwo:"]];
例如:one工程程序中:(调用openURL)
//
// ViewController.m
// 程序间通讯OneProduct
//
// Created by dllo on 16/3/24.
// Copyright © 2016年 HaiTeng. All rights reserved.
//
#import "ViewController.h"
@interface ViewController ()
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
self.view.backgroundColor = [UIColor grayColor];
}
- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{
// ProductTwo:(你自己的工程名)name=xx&age=xx(你想传的参数用&连接多参数)
//注意:参数中不可有中文
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"ProductTwo://name=xx&age=xx"]];
/*
LaunchServices: ERROR: There is no registered handler for URL scheme ProductTwo
程序间通讯:前提 保证手机上两款app同时存在
*/
}
@end
3 然后事件收到相应,你会接到这样的提示,说明你成功了
注意:
/*
LaunchServices: ERROR: There is no registered handler for URL scheme ProductTwo
程序间通讯:前提 保证手机上两款app同时存在
*/
///////当然仅仅这样然而没什么软用,通常我们借用程序间通讯进而进行传值
two程序中:(在AppDelegate)
//
// AppDelegate.m
// 程序间通讯TwoProduct
//
// Created by dllo on 16/3/24.
// Copyright © 2016年 HaiTeng. All rights reserved.
//
#import "AppDelegate.h"
@interface AppDelegate ()
@end
@implementation AppDelegate
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// Override point for customization after application launch.
return YES;
}
//ios9.0之前(目前已废弃)
//- (BOOL)application:(UIApplication *)application handleOpenURL:(NSURL *)url{
// return YES;
//}
//ios9.0推荐使用此方法(最新,程序One跳到我的时候, 在此方法中,我可以接受到它传过来的值,进行一些操作)
- (BOOL)application:(UIApplication *)app openURL:(NSURL *)url options:(NSDictionary<NSString *,id> *)options{
//解码
NSString *recetext = [url.host stringByRemovingPercentEncoding];
NSLog(@"%@",recetext); //打印看看One程序传过来的值
//若想回传到OneProduct可执行此方法(同样在OneProduct工程的appdelegate 中写openUrl方法即可得到我穿回来的参数)
[self performSelector:@selector(goBackOneProduct:) withObject:nil afterDelay:2];
return YES;
}
- (void)goBackOneProduct:(id)object{
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"ProductOne://name=TwoProductSendData&age=xx"]];
}
@end
//总结:
说白了就是,调用此代码 [[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"ProductOne://name=TwoProductSendData&age=xx"]];
通过URL Schemes 标识 进行跳转
原文:http://www.cnblogs.com/HaiTeng/p/5323870.html