从一个app跳转到另一个app

来源:互联网 发布:php 500错误日志 打印 编辑:程序博客网 时间:2024/05/02 01:51


通过openURL启动第三方app并传参数

← iOS 5.1.1怎样去掉锁屏界面的相机快捷图标?

iOS越狱原理 →

通过openURL启动第三方app并传参数

Posted on 2012 年 6 月 4 日 by rainbird


 Download this page in PDF format

转自:http://lifeinbeta.diandian.com/post/2012-05-31/40028982809

=====工程A=====0. 建立工程A, 先调出URL Types1.Add Row 一个URL Schemes 并随便起个名字 (这就是调用这个app的唯一链接)2. 在工程A的AppDelegate.m里加入以下系统方法:(这个方法会捕获调用本工程的程序传递过来的URL identifier文本)

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

{

  // 处理传递过来的参数

  UIAlertView *alertView;

  NSString*text = [[url host] stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding];

  alertView = [[UIAlertView alloc] initWithTitle:@"Text"

                                         message:text                            

                                        delegate:nil

                               cancelButtonTitle:@"OK"

                               otherButtonTitles:nil];

    [alertView show];

    [alertView release];

    return YES;

}

====工程B=====3. 建立工程B, 添加调用语句:

[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"myapp://foo=444bar=222"]];

4. 编译运行工程B, 结果是:B启动->A启动->A弹出Alert:

另外:0. 从结果看出app的地址构成是: URL Scheme://URL identifier1. 单用URL Scheme 即可打开程序, 即URL identifier是可选的2. myapp://后面的字 可以为点”.”和等号”=” 不可以为空格和问号3. stackoverflow上有很多人指出这是apple禁止的功能, 所以请谨慎使用, 但如果是客户问”设备能力”这方面的问题, 那么答案是”可以”, 但 不建议那么做.

0 0
原创粉丝点击