两个App之间的互相交互传值

1、首先建两个工程,并且在info中分别设置URL Schemes为 ApplicationFirst 和 ApplicationSecond

2、在appdelegate中添加方法

// 有外部app通过URL Scheme 的方法打开本应用,就会走本应用的这个方法

- (BOOL)application:(UIApplication *)application handleOpenURL:(NSURL *)url

{

NSString *test = url.host; // 这就是参数

NSLog(@"host = %@",test);

NSLog(@"url = %@", url);

return YES;

}

3、拉个按钮出来,并写出跳转方法

- (void)clickBtn:(UIButton *)sender {

NSString *paramStr = [NSString stringWithFormat:@"ApplicationSecond://%@",self.testLabel.text];

NSURL *url = [NSURL URLWithString:[paramStr stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];

[[UIApplication sharedApplication] openURL:url];

NSLog(@"打开第二个应用");

}

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容