星空网 > 软件开发 > 操作系统

iOS App之间跳转

1.先来看看效果,这里做了三个功能

  1. 从MyApp跳转到YourApp
  2. 从MyApp跳转到YourApp的指定页面
  3. 从YourApp使用跳转url的方式跳回MyApp

iOS App之间跳转images/loading.gif' data-original="http://images2015.cnblogs.com/blog/800567/201603/800567-20160325102501683-160372884.gif" />

2.实现app之间的跳转需要注意两方面

  1. 实现跳转的代码
  2. 配置url及url白名单

3首先来讲url和白名单的设置

  1. 创建两个工程分别叫MyApp和YourApp
  2. 设置MyApp的url,设置的方法有两种,都是等效的,如下图
    1. iOS App之间跳转
    2. iOS App之间跳转
  3. 设置YourApp的url
    1. iOS App之间跳转
  4. 设置MyApp的白名单
    1. 在info.plist中添加LSApplicationQueriesSchemes的数组,其中有含有一个string类型的数据,即为你要跳转的另外一个App的url,我们要从MyApp跳转到YourApp,我们把YourApp的url设置为your,所以这里要写入YourApp的url“your”
    2. iOS App之间跳转
  5. 设置YourApp的白名单,我写的demo中有添加用url跳转回MyApp的功能所以要设置YourApp的白名单,如果没有的话是不用设置的,系统自带的有跳转回初始APP的方法
    1. iOS App之间跳转
  6. 注意不要把白名单的key写错了

4.实现跳转的代码

  1. MyApp中的代码
    1. - (IBAction)gotoYoueApp:(UIButton *)sender {  // 1.获取application对象  UIApplication *app = [UIApplication sharedApplication];    // 2.创建要打开的应用程序的URL  NSURL *url = [NSURL URLWithString:@"your://aaa"];    // 3.判断是否可以打开另一个应用  if ([app canOpenURL:url]) {    // 能,就打开    [app openURL:url];  }else{    NSLog(@"打开应用失败");  }}

  2.  YourApp中的代码
    1. 写在AppDelegate.m中
    2. //如果是通过URL打开的本应用,则下面的方**被执行-(BOOL)application:(UIApplication *)application handleOpenURL:(NSURL *)url{  //获取window中加载的根视图,也就是那个导航  UINavigationController *navi = (UINavigationController *)self.window.rootViewController;  //为了触发push第二个界面的segue,需要拿到  //左边灰色背景的那个控制器的引用  //而灰色的那个控制器是navi的根视图控制器  //vc代表灰色的那个界面  ViewController *vc = (ViewController *)navi.topViewController;    //1.获取请求的URL地址  NSString *urlString = [url absoluteString];    //2.判断地址中包含的信息为bbb则打开第二个页面  if ([urlString hasPrefix:@"your://bbb"])  {    [vc performSegueWithIdentifier:@"pushWhiteSegue" sender:nil];  }    return YES;}//新的用于响应从URL跳转过来的方法-(BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation{  //获取window中加载的根视图,也就是那个导航  UINavigationController *navi = (UINavigationController *)self.window.rootViewController;  //为了触发push第二个界面的segue,需要拿到  //左边灰色背景的那个控制器的引用  //而灰色的那个控制器是navi的根视图控制器  //vc代表灰色的那个界面  ViewController *vc = (ViewController *)navi.topViewController;    //1.获取请求的URL地址  NSString *urlString = [url absoluteString];    //2.判断地址中包含的信息为bbb则打开第二个页面  if ([urlString hasPrefix:@"your://bbb"])  {    [vc performSegueWithIdentifier:@"pushWhiteSegue" sender:nil];  }  return YES;}

       

    3. 想要跳转到MyApp的时候
    4. - (IBAction)goBackMyApp:(id)sender {  UIApplication *app = [UIApplication sharedApplication];  NSURL *url = [NSURL URLWithString:@"my://"];  if ([app canOpenURL:url]) {    [app openURL:url];  }else{    NSLog(@"跳回到myapp失败");  }}

 5.demo:https://github.com/TigerCui/MyAppJumpToYourApp.git




原标题:iOS App之间跳转

关键词:IOS

IOS
*特别声明:以上内容来自于网络收集,著作权属原作者所有,如有侵权,请联系我们: admin#shaoqun.com (#换成@)。

易达海外仓怎么样:https://www.goluckyvip.com/tag/47624.html
易达恒通:https://www.goluckyvip.com/tag/47625.html
易达恒通供应链:https://www.goluckyvip.com/tag/47626.html
易达全球:https://www.goluckyvip.com/tag/47627.html
易达全球物流:https://www.goluckyvip.com/tag/47628.html
易达天下:https://www.goluckyvip.com/tag/47629.html
新喀里多尼亚/new caledonia:https://www.kjdsnews.com/a/1836448.html
美国对13家与俄罗斯相关的加密货币金融科技公司实施制裁:https://www.kjdsnews.com/a/1836449.html
相关文章
我的浏览记录
最新相关资讯
海外公司注册 | 跨境电商服务平台 | 深圳旅行社 | 东南亚物流