标签:des style blog http io color ar os sp
如要实现项目A里点击一个Button,跳到项目B:
1. 项目B里info.plist设置:
2. 在项目B的Appdelegate里实现方法:
/** * BProject AppDelegate */ - (BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation { UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:url.scheme message:url.description delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:url.query, url.host, nil]; [alertView show]; return YES; }
3. 项目A里Button的点击事件:
- (IBAction)jumpToAnotherApp:(id)sender { NSString *urlString = @"BProject://www.CompanyName.BProject?SendSomeDataToBProject"; NSURL *URL = [NSURL URLWithString:urlString]; [[UIApplication sharedApplication] openURL:URL]; }
4. 模拟器或真机上运行项目B,再运行项目A,点击Button,效果:
例如跳到淘宝应用:
NSString *urlString = @"taobao://";
查找想要通信的应用的URL Schemes:
用itools下载该应用的info.plist,比如想跳到当当网app,
打开当当网app的info.plist是:
在点击事件里实现
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"dangdang://"]];
或者
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"dd://"]];
都可以跳转到当当网app。
若手机没安装要跳转的app, 比如想跳转到人人网App,但手机没安装这个软件,可以:
1). 从苹果网站 https://linkmaker.itunes.apple.com/us/?urlDesc= 先查找出人人网的AppStore链接,
https://itunes.apple.com/cn/app/ren-ren/id316709252?mt=8&uo=4
2). 点击事件中加入判断代码:
if ([[UIApplication sharedApplication] canOpenURL:[NSURL URLWithString:@"renrenios://"]]) {
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"renrenios://"]];
} else {
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"https://itunes.apple.com/cn/app/ren-ren/id316709252?mt=8&uo=4"]];
}
这样,大概可以完成应用之间的通信。
标签:des style blog http io color ar os sp
原文地址:http://www.cnblogs.com/dfm1212/p/4075723.html