ios推送跳转到指定页面

//获取当前屏幕显示的viewcontroller
- (UIViewController *)getCurrentVC
{
    UIViewController  *result = nil;
    UIWindow * window = [[UIApplication sharedApplication] keyWindow];
    if(window.windowLevel != UIWindowLevelNormal)
    {
        NSArray *windows = [[UIApplication sharedApplication] windows];
        for(UIWindow * tmpWin in windows)
        {
            if(tmpWin.windowLevel == UIWindowLevelNormal)
            {
                window = tmpWin;
                break;
            }
        }
    }
    UIView *frontView = [[window subviews] objectAtIndex:0];
    id nextResponder = [frontView nextResponder];
    if([nextResponder isKindOfClass:[UIViewController class]]){
        result = nextResponder;
    }else{
        result = window.rootViewController;
    }
    return result;
}

//找到当前控制器  判断
- (UIViewController *)getDisViewController
{
    UIViewController *currVC;
    if ([[self getCurrentVC] isKindOfClass:[SystemViewController class]]) {//判断是是不是tabbar  是tabbar找到最好导航最后一个控制器是当前控制器
        SystemViewController *tabBar = (SystemViewController *)[self getCurrentVC];
        SystemNavigationController *mainNC = tabBar.selectedViewController;
        return mainNC.viewControllers.lastObject;
    }
    /*else if ([ [self getCurrentVC] isKindOfClass:[WJInterpreterTabBarController class]])
    {
        WJInterpreterTabBarController *tabBar = (WJInterpreterTabBarController *)[self getCurrentVC];
        WJNAVController *mainNC = tabBar.selectedViewController;
        return mainNC.viewControllers.lastObject;
    }*/
     else if ([ [self getCurrentVC] isKindOfClass:[SystemNavigationController class]]){//如果当前页面是导航,找到导航数组中最后一个控制器 ,是当前屏幕显示的控制器
        SystemNavigationController *mainNC = (SystemNavigationController *)[self getCurrentVC];
        return mainNC.viewControllers.lastObject;
    }else if ([ [self getCurrentVC] isKindOfClass:[UIViewController class]]){
        return [self getCurrentVC] ;
    }else{
        return [self getCurrentVC] ;
    }
}

//获取到控制器  直接跳转
UIViewController *vc = [self getDisViewController];
        [vc.navigationController pushViewController:systemMessageVC animated:YES];

你可能感兴趣的:(ios推送跳转到指定页面)