IOS接入如何获取viewController
将如下代码贴入oc代码
- (UIWindow*)keyWindow
{
UIWindow *foundWindow = nil;
NSArray *windows = [[UIApplication sharedApplication]windows];
for (UIWindow *window in windows) {
if (window.isKeyWindow) {
foundWindow = window;
break;
}
}
return foundWindow;
}
- (UIViewController *)currentViewController {
UIWindow *keyWindow = [self keyWindow];//[UIApplication sharedApplication].keyWindow;
UIViewController *vc = keyWindow.rootViewController;
while (vc.presentedViewController) {
vc = vc.presentedViewController;
if ([vc isKindOfClass:[UINavigationController class]]) {
vc = [(UINavigationController *)vc visibleViewController];
} else if ([vc isKindOfClass:[UITabBarController class]]) {
vc = [(UITabBarController *)vc selectedViewController];
}
}
return vc;
}
参考阿里云金融实人认证文档,通过以下代码传入当前viewController,用于展现网络加载和presentViewController。
//传入当前viewController,用于展现请求网络时的菊花。
[extParams setValue:[self currentViewController] forKey:@"currentCtr"];
如果觉得对你有帮助,欢迎打赏