通过制定连接打开APP中指定的页面处理方法

在项目中经常需要使用到扫描二维码后根据是否安装app进行不同的操作.有的是跳转到指定的页面,有的是需要去下载app的页面.如何进行目的性跳转:

//在AppDelegate.m中的openURL方法中进行操作,这个方法是通过url与应用进行交互时会调用的方法

- (BOOL)application:(UIApplication *)app openURL:(NSURL *)url options:(NSDictionary<UIApplicationOpenURLOptionsKey, id> *)options {
 //这里边的 ycxdrive是我前端h5工程师约定的URL Schemes,是一个约定好的名字
 if ([[url absoluteString] rangeOfString:@"ycxdrive"].location == 0) {
//type userId都是我们前段及移动端约定好url上锁携带的信息字段
     NSRange range = [string rangeOfString:@"type"];//匹配得到的下标
        string = [string substringFromIndex:range.location];//截取掉下标7之后的字符串
        NSArray *array = [string componentsSeparatedByString:@"&"]; //从符号&中分隔成2个元素的数组
        NSMutableDictionary *APPInfoDicAboutFriend = [NSMutableDictionary dictionary];
        [array enumerateObjectsUsingBlock:^(NSString *obj, NSUInteger idx, BOOL * _Nonnull stop) {
            if ([obj containsString:@"type"]) {
                NSRange typeRange = [obj rangeOfString:@"="];//匹配得到的下标
                NSString *typeString = [obj substringFromIndex:typeRange.location+1];//截取掉下标7之后的字符串
                [APPInfoDicAboutFriend setObject:typeString forKey:@"type"];
            }else if ([obj containsString:@"userId"]){
                NSRange userIDRange = [obj rangeOfString:@"="];//匹配得到的下标
                NSString *userIDString = [obj substringFromIndex:userIDRange.location+1];//截取掉下标7之后的字符串
                [APPInfoDicAboutFriend setObject:userIDString forKey:@"userId"];
            }
        }];
        //根据上述条件进行制定页面的跳转
        // 跳转用户主页,本人使用的tabbarVC控制器作为主控制器所以这么操作
        YCXRootTabBarController *rootTabVC = (YCXRootTabBarController *)self.window.rootViewController;
        rootTabVC.selectedIndex = 3;
        [rootTabVC.viewControllers enumerateObjectsUsingBlock:^(__kindof UIViewController * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
            YCXBaseNavigationController *baseVC = obj;
            if ([baseVC.viewControllers[0] isKindOfClass:[YCXProfileController class]]) {
                YCXProfileController *profileVC = baseVC.viewControllers[0];
                //需要跳转到 ProfileController下的PersonalProfileController中
                PersonalProfileController *vc = [[PersonalProfileController alloc] initWithNibName:@"PersonalProfileController" bundle:nil];

                [profileVC.navigationController pushViewController:vc animated:YES];
                }
            }];
        }
    }
    return YES;
 }
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值