美文网首页iOS程序猿iOS Developer
ios 极光推送获取当前控制器进行界面跳转

ios 极光推送获取当前控制器进行界面跳转

作者: 亦暖易冷 | 来源:发表于2017-03-29 09:27 被阅读115次
    #pragma mark - 通过推送返回的数据决定跳转到那个页面
    - (void)JPushjudgeToWhichVC{
        if ([self.type isEqualToString:@"1"]) {
            //外链和APP内活动页
            KindDetailViewController * KindVC = [[KindDetailViewController alloc] init];
            KindVC.url = self.redirect;
            [[self getCurrentVC] presentViewController:KindVC animated:YES completion:nil];
            
        }
    }
    
    #pragma mark - 获取当前的显示的控制器
    - (UIViewController *)getCurrentVC{
    
        UIViewController *currVC = nil;
        UIViewController *rootvc = self.window.rootViewController;
        do {
            if ([Rootvc isKindOfClass:[UINavigationController class]]) {//控制器为UINavigationController
                UINavigationController *nav = (UINavigationController *)rootvc;
                UIViewController *vc = [nav.viewControllers lastObject];
                currVC = vc;
                rootvc = vc.presentedViewController;
                
            }else if ([Rootvc isKindOfClass:[UITabBarController class]]){//控制器为UITabBarController
                UITabBarController *tabVC = (UITabBarController *)rootvc;
                currVC = tabVC ;
                rootvc = [tabVC.viewControllers objectAtIndex:tabVC.selectedIndex];
                continue;
            }else {//控制器为UIViewController
                UIViewController *VC = (UIViewController *)rootvc;
                currVC = VC;
                Rootvc = VC.presentedViewController;
            }
        } while (Rootvc != nil);
        return currVC;
    }
    

    参考资料http://www.jianshu.com/p/a277790c9dc4 在其原有基础上多添加了一个当前控制是UIViewController 的判断和处理

    相关文章

      网友评论

        本文标题:ios 极光推送获取当前控制器进行界面跳转

        本文链接:https://www.haomeiwen.com/subject/hznugttx.html