#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 的判断和处理
网友评论