iOS接收到推送消息的跳转方法
在做推送的时候,往往在appdelegate里面接收到消息,跳转很麻烦,这里就介绍一种简单的跳转方法
首先,获取当前的停留的VC
- (UIViewController *)topVC:(UIViewController *)rootViewController{ if ([rootViewController isKindOfClass:[UITabBarController class]]) { UITabBarController *tab = (UITabBarController *)rootViewController; return [self topVC:tab.selectedViewController]; }else if ([rootViewController isKindOfClass:[UINavigationController class]]){ UINavigationController *navc = (UINavigationController *)rootViewController; return [self topVC:navc.visibleViewController]; }else if (rootViewController.presentedViewController){ UIViewController *pre = (UIViewController *)rootViewController.presentedViewController; return [self topVC:pre]; }else{ return rootViewController; } }
调用方法:
UIViewController *vc = [self topVC:[UIApplication sharedApplication].keyWindow.rootViewController];
然后执行跳转就可以了