// // AdBase.m // XenonSDK // // Created by fq on 2020/12/23. // Copyright © 2020 SAGESSE. All rights reserved. // #import "AdBase.h" @implementation AdBase - (instancetype)init { self = [super init]; if (self) { self.weight = 1; } return self; } -(BOOL)isReady { return NO; } -(UIWindow*)currentWindow{ id appDelegate = [UIApplication sharedApplication].delegate; if (appDelegate && [appDelegate respondsToSelector:@selector(window)]) { return [appDelegate window]; } NSArray *windows = [UIApplication sharedApplication].windows; if ([windows count] == 1) { return [windows firstObject]; } else { for (UIWindow *window in windows) { if (window.windowLevel == UIWindowLevelNormal) { return window; } } } return nil; } - (UIViewController *)currentViewController { UIWindow *window = [[UIApplication sharedApplication].delegate window]; UIViewController *topViewController = [window rootViewController]; while (true) { if (topViewController.presentedViewController) { topViewController = topViewController.presentedViewController; } else if ([topViewController isKindOfClass:[UINavigationController class]] && [(UINavigationController*)topViewController topViewController]) { topViewController = [(UINavigationController *)topViewController topViewController]; } else if ([topViewController isKindOfClass:[UITabBarController class]]) { UITabBarController *tab = (UITabBarController *)topViewController; topViewController = tab.selectedViewController; } else { break; } } return topViewController; } @end