美文网首页
两个App之间的互相交互传值

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

作者: 逆枫0 | 来源:发表于2016-09-02 17:10 被阅读447次

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(@"打开第二个应用");

}

相关文章

网友评论

      本文标题:两个App之间的互相交互传值

      本文链接:https://www.haomeiwen.com/subject/txfkettx.html