//在basicViewControler 的viewDidAppear 调用请求就可以了
不需要获取驶入控制器
calss name 就是当前vc的名字
- (UIViewController *)visibleViewControllerIfExist {
if (self.presentedViewController) {
return [self.presentedViewController visibleViewControllerIfExist];
}
if ([self isKindOfClass:[UINavigationController class]]) {
return [((UINavigationController *)self).visibleViewController visibleViewControllerIfExist];
}
if ([self isKindOfClass:[UITabBarController class]]) {
return [((UITabBarController *)self).selectedViewController visibleViewControllerIfExist];
}
if ([self isViewLoaded] && self.view.window) {
return self;
} else {
NSLog(@"DGVisibleViewControllerIfExist:,找不到可见的viewController。self = %@, self.view.window = %@", self, self.view.window);
return nil;
}
}
+ (nullable UIViewController *)currentVisibleViewController{
UIViewController *rootViewController = [UIApplication sharedApplication].delegate.window.rootViewController;
UIViewController *visibleViewController = [rootViewController visibleViewControllerIfExist];
return visibleViewController;
}