1.两个 App之间的跳转
场景:App1通过点击按钮跳转到App2
首先在App2中选择项目App2 -> TARGETS -> Info -> URL Types -> URL Schemes,设置App-2的URL Schemes为App2
然后在App1中实现跳转逻辑
- (IBAction)jumpToApp2:(id)sender {
// 1.获取应用程序App2的URL Scheme
NSURL *app2Url = [NSURL URLWithString:@"App2://"];
// 2.判断手机中是否安装了对应程序
if ([[UIApplication sharedApplication] canOpenURL:app2Url]) {
// 3. 打开应用程序App2
[[UIApplication sharedApplication] openURL:app2Url];
} else {
NSLog(@"没有安装App2");
}
}
2.通过网页跳转App
场景:通过App分享出去的某个网页,点击网页上的某个按钮可以打开App
首先和上面一样设置App的URL Schemes,
然后在网页中添加
<body>
<a href="https://itunes.apple.com/cn/app/ju53you-pin-fen-xiao-jian/id1080605326?mt=8" id="openApp">打开app</a>
<script type="text/javascript">
document.getElementById('openApp').onclick = function(e){
var ifr = document.createElement('iframe');
ifr.src = 'App2://showMessage?https://www.baidu.com';
ifr.style.display = 'none';
document.body.appendChild(ifr);
window.setTimeout(function(){
document.body.removeChild(ifr);
},3000)
};
</script>
</body>
3.将App获取到的文件通过其他App打开
场景:在App1中下载的pdf文件(除了图片和视频的其他文件),通过QQ或者微信发给好友.
//先将下载到的文件放在本地沙盒
//然后将下面代码放在按钮点击方法里
UIDocumentInteractionController *documentController = [UIDocumentInteractionController interactionControllerWithURL:[[NSBundle mainBundle] URLForResource:@"MyFile" withExtension:@"pdf"]];
[documentController presentOpenInMenuFromRect:self.view.bounds inView:self.view animated:YES];