+ (UIViewController *)kzp_getRootViewController{
UIWindow* window = nil;
if (@available(iOS 13.0, *)) {
for (UIWindowScene* windowScene in [UIApplication sharedApplication].connectedScenes){
if (windowScene.activationState == UISceneActivationStateForegroundActive){
window = windowScene.windows.firstObject;
break;
}
}
}else{
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
// 这部分使用到的过期api
window = [UIApplication sharedApplication].keyWindow;
#pragma clang diagnostic pop
}
if([window.rootViewController isKindOfClass:NSNull.class]){
return nil;
}
return window.rootViewController;
}
网友评论