应用间的相互跳转
来源:互联网 发布:淘宝类目搜索排名 编辑:程序博客网 时间:2024/05/19 16:47
打开其他应用,需要给被打开应用设置schemes:自定义的协议头。
跳转的代码如下:
- (IBAction)skipToWechat { [self openURLWithString:@"mywechat://"];}- (IBAction)skipToTimeline { [self openURLWithString:@"mywechat://timeline?news"];}- (IBAction)skipToSession { [self openURLWithString:@"mywechat://session?news"];}- (void)openURLWithString:(NSString *)urlString{ // 1.获取到对应应用程序的URL NSURL *wechatURL = [NSURL URLWithString:urlString]; // 2.判断手机中是否安装了对应的应用程序 if ([[UIApplication sharedApplication] canOpenURL:wechatURL]) { // 3.打开应用程序 [[UIApplication sharedApplication] openURL:wechatURL]; }}
注:@”@”mywechat://timeline?news”中的?前边的mywechat://timeline是要跳转到协议头为myweichat的应用中的timeline页面,后边的news是当前应用的协议头。
跳转后,到目的应用中的AppDelegate类中获取协议,并且半段跳转到什么页面,代码如下:
- (BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation{ // self.url = url.absoluteString; // 1.将URL转成字符串 NSString *urlString = url.absoluteString; // 获取到主页控制器 UINavigationController *rootNav = (UINavigationController *)self.window.rootViewController; [rootNav popToRootViewControllerAnimated:NO]; ViewController *homeVc = [rootNav.childViewControllers firstObject]; homeVc.urlString = urlString; // 2.判断是通过朋友圈还是微信好友跳转过来 if ([urlString containsString:@"timeline"]) { [homeVc performSegueWithIdentifier:@"homeToTimeline" sender:nil]; } else if ([urlString containsString:@"session"]){ [homeVc performSegueWithIdentifier:@"homeToSession" sender:nil]; } return YES;}
从目的应用,跳回到原应用,就用到了收到的协议?后的参数,需要注意的是拼接完整协议头,代码如下:
- (IBAction)backToApp { // 0.拿到对应应用程序的urlScheme(wechat://session?news) /* NSRange range = [self.urlString rangeOfString:@"?"]; range.location; self.urlString substringFromIndex:range.location */ NSString *urlSchemeString = [[self.urlString componentsSeparatedByString:@"?"] lastObject]; NSString *urlString = [urlSchemeString stringByAppendingString:@"://"]; // 1.获取对应应用程序的URL NSURL *url = [NSURL URLWithString:urlString]; // 2.判断是否可以打开 if ([[UIApplication sharedApplication] canOpenURL:url]) { [[UIApplication sharedApplication] openURL:url]; }}
转载请注明出处,万分感谢!
阅读全文
0 0
- 应用间的相互跳转
- 应用的相互跳转
- 两个iOS 应用间的相互跳转
- iOS应用间相互跳转
- iOS应用间相互跳转
- iOS应用间相互跳转
- iOS应用间相互跳转
- iOS应用间相互跳转
- iOS 应用间相互跳转
- ios 开发不同应用间相互跳转
- 应用间相互跳转(URL Schemes)
- 应用之间相互调用,应用相互跳转,应用间传递参数
- 两个应用之间相互跳转
- ios app间的相互跳转
- 应用间的跳转
- iOS两个应用之间相互跳转
- iOS 两应用之间相互跳转
- iOS 应用之间相互跳转URL Schemes
- 已有项目依赖cordovaLib打包后调用插件崩溃问题
- js遍历树算出树的深度
- RabbitMQ的权限设置
- 原码补码反码——复习
- python 列出目录下的文件
- 应用间的相互跳转
- 深入理解操作系统原理之Windows进程管理
- Vue1.0学习总结(1)———指令、事件、绑定属性、模板、过滤器
- package control: install提示There Are No Packages Available For Installation
- https://stackoverflow.com/questions/37505484/cant-exit-git-commit-in-windows
- Mybatis Generator相关xml配置文件含义解析
- Ubuntu使用教程:E: 无法获得锁 /var/lib/apt/lists/lock
- Chapter 8 NP-complete problems课后习题8.16
- materialDesign过度动画