GMTools.m 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. //
  2. // GMTools.m
  3. // XenonSDK
  4. //
  5. // Created by fq on 2021/3/22.
  6. // Copyright © 2021 SAGESSE. All rights reserved.
  7. //
  8. #import "GMTools.h"
  9. @implementation GMTools
  10. + (UIViewController *)getViewControl {
  11. UIWindow *window = [[UIApplication sharedApplication].delegate window];
  12. UIViewController *topViewController = [window rootViewController];
  13. while (true) {
  14. if (topViewController.presentedViewController) {
  15. topViewController = topViewController.presentedViewController;
  16. } else if ([topViewController isKindOfClass:[UINavigationController class]] && [(UINavigationController*)topViewController topViewController]) {
  17. topViewController = [(UINavigationController *)topViewController topViewController];
  18. } else if ([topViewController isKindOfClass:[UITabBarController class]]) {
  19. UITabBarController *tab = (UITabBarController *)topViewController;
  20. topViewController = tab.selectedViewController;
  21. } else {
  22. break;
  23. }
  24. }
  25. return topViewController;
  26. }
  27. + (UIWindow *)getKeyWindow {
  28. UIWindow *mainWindow = nil;
  29. if (@available(iOS 13.0, *)) {
  30. mainWindow = [UIApplication sharedApplication].windows.firstObject;
  31. [mainWindow makeKeyWindow];
  32. }else {
  33. mainWindow = [UIApplication sharedApplication].keyWindow;
  34. }
  35. return mainWindow;
  36. }
  37. + (BOOL)isIPhoneXSeries {
  38. BOOL isPhoneX = NO;
  39. if (@available(iOS 11.0, *)) {
  40. isPhoneX = [[UIApplication sharedApplication] delegate].window.safeAreaInsets.bottom > 0.0? YES:NO;
  41. }
  42. return isPhoneX;
  43. }
  44. @end