UnityAppController.mm 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565
  1. #import "UnityAppController.h"
  2. #import "UnityAppController+ViewHandling.h"
  3. #import "UnityAppController+Rendering.h"
  4. #import "iPhone_Sensors.h"
  5. #import <CoreGraphics/CoreGraphics.h>
  6. #import <QuartzCore/QuartzCore.h>
  7. #import <QuartzCore/CADisplayLink.h>
  8. #import <Availability.h>
  9. #import <OpenGLES/EAGL.h>
  10. #import <OpenGLES/EAGLDrawable.h>
  11. #import <OpenGLES/ES2/gl.h>
  12. #import <OpenGLES/ES2/glext.h>
  13. #include <mach/mach_time.h>
  14. // MSAA_DEFAULT_SAMPLE_COUNT was moved to iPhone_GlesSupport.h
  15. // ENABLE_INTERNAL_PROFILER and related defines were moved to iPhone_Profiler.h
  16. // kFPS define for removed: you can use Application.targetFrameRate (30 fps by default)
  17. // DisplayLink is the only run loop mode now - all others were removed
  18. #include "CrashReporter.h"
  19. #include "UI/OrientationSupport.h"
  20. #include "UI/UnityView.h"
  21. #include "UI/Keyboard.h"
  22. #include "UI/SplashScreen.h"
  23. #include "Unity/InternalProfiler.h"
  24. #include "Unity/DisplayManager.h"
  25. #include "Unity/EAGLContextHelper.h"
  26. #include "Unity/GlesHelper.h"
  27. #include "Unity/ObjCRuntime.h"
  28. #include "PluginBase/AppDelegateListener.h"
  29. #include <assert.h>
  30. #include <stdbool.h>
  31. #include <sys/types.h>
  32. #include <unistd.h>
  33. #include <sys/sysctl.h>
  34. #import <FitfunSDK/FitfunSDK.h>
  35. #import "IOSPlatformSDK.h"
  36. //
  37. UnityAppController* _UnityAppController = nil;
  38. // Standard Gesture Recognizers enabled on all iOS apps absorb touches close to the top and bottom of the screen.
  39. // This sometimes causes an ~1 second delay before the touch is handled when clicking very close to the edge.
  40. // You should enable this if you want to avoid that delay. Enabling it should not have any effect on default iOS gestures.
  41. #define DISABLE_TOUCH_DELAYS 1
  42. // we keep old bools around to support "old" code that might have used them
  43. bool _ios42orNewer = false, _ios43orNewer = false, _ios50orNewer = false, _ios60orNewer = false, _ios70orNewer = false;
  44. bool _ios80orNewer = false, _ios81orNewer = false, _ios82orNewer = false, _ios83orNewer = false, _ios90orNewer = false, _ios91orNewer = false;
  45. bool _ios100orNewer = false, _ios101orNewer = false, _ios102orNewer = false, _ios103orNewer = false;
  46. bool _ios110orNewer = false, _ios111orNewer = false, _ios112orNewer = false;
  47. // was unity rendering already inited: we should not touch rendering while this is false
  48. bool _renderingInited = false;
  49. // was unity inited: we should not touch unity api while this is false
  50. bool _unityAppReady = false;
  51. // see if there's a need to do internal player pause/resume handling
  52. //
  53. // Typically the trampoline code should manage this internally, but
  54. // there are use cases, videoplayer, plugin code, etc where the player
  55. // is paused before the internal handling comes relevant. Avoid
  56. // overriding externally managed player pause/resume handling by
  57. // caching the state
  58. bool _wasPausedExternal = false;
  59. // should we skip present on next draw: used in corner cases (like rotation) to fill both draw-buffers with some content
  60. bool _skipPresent = false;
  61. // was app "resigned active": some operations do not make sense while app is in background
  62. bool _didResignActive = false;
  63. // was startUnity scheduled: used to make startup robust in case of locking device
  64. static bool _startUnityScheduled = false;
  65. bool _supportsMSAA = false;
  66. #if UNITY_SUPPORT_ROTATION
  67. // Required to enable specific orientation for some presentation controllers: see supportedInterfaceOrientationsForWindow below for details
  68. NSInteger _forceInterfaceOrientationMask = 0;
  69. #endif
  70. @implementation UnityAppController
  71. @synthesize unityView = _unityView;
  72. @synthesize unityDisplayLink = _displayLink;
  73. @synthesize rootView = _rootView;
  74. @synthesize rootViewController = _rootController;
  75. @synthesize mainDisplay = _mainDisplay;
  76. @synthesize renderDelegate = _renderDelegate;
  77. @synthesize quitHandler = _quitHandler;
  78. #if UNITY_SUPPORT_ROTATION
  79. @synthesize interfaceOrientation = _curOrientation;
  80. #endif
  81. - (id)init
  82. {
  83. if ((self = _UnityAppController = [super init]))
  84. {
  85. // due to clang issues with generating warning for overriding deprecated methods
  86. // we will simply assert if deprecated methods are present
  87. // NB: methods table is initied at load (before this call), so it is ok to check for override
  88. NSAssert(![self respondsToSelector: @selector(createUnityViewImpl)],
  89. @"createUnityViewImpl is deprecated and will not be called. Override createUnityView"
  90. );
  91. NSAssert(![self respondsToSelector: @selector(createViewHierarchyImpl)],
  92. @"createViewHierarchyImpl is deprecated and will not be called. Override willStartWithViewController"
  93. );
  94. NSAssert(![self respondsToSelector: @selector(createViewHierarchy)],
  95. @"createViewHierarchy is deprecated and will not be implemented. Use createUI"
  96. );
  97. }
  98. return self;
  99. }
  100. - (void)setWindow:(id)object {}
  101. - (UIWindow*)window { return _window; }
  102. - (void)shouldAttachRenderDelegate {}
  103. - (void)preStartUnity {}
  104. - (void)startUnity:(UIApplication*)application
  105. {
  106. NSAssert(_unityAppReady == NO, @"[UnityAppController startUnity:] called after Unity has been initialized");
  107. UnityInitApplicationGraphics();
  108. // we make sure that first level gets correct display list and orientation
  109. [[DisplayManager Instance] updateDisplayListInUnity];
  110. UnityLoadApplication();
  111. Profiler_InitProfiler();
  112. [self showGameUI];
  113. [self createDisplayLink];
  114. [IOSPlatformSDK sharedInstance];
  115. UnitySetPlayerFocus(1);
  116. }
  117. extern "C" void UnityDestroyDisplayLink()
  118. {
  119. [GetAppController() destroyDisplayLink];
  120. }
  121. extern "C" void UnityRequestQuit()
  122. {
  123. _didResignActive = true;
  124. if (GetAppController().quitHandler)
  125. GetAppController().quitHandler();
  126. else
  127. exit(0);
  128. }
  129. #if UNITY_SUPPORT_ROTATION
  130. - (NSUInteger)application:(UIApplication*)application supportedInterfaceOrientationsForWindow:(UIWindow*)window
  131. {
  132. // No rootViewController is set because we are switching from one view controller to another, all orientations should be enabled
  133. if ([window rootViewController] == nil)
  134. return UIInterfaceOrientationMaskAll;
  135. // Some presentation controllers (e.g. UIImagePickerController) require portrait orientation and will throw exception if it is not supported.
  136. // At the same time enabling all orientations by returning UIInterfaceOrientationMaskAll might cause unwanted orientation change
  137. // (e.g. when using UIActivityViewController to "share to" another application, iOS will use supportedInterfaceOrientations to possibly reorient).
  138. // So to avoid exception we are returning combination of constraints for root view controller and orientation requested by iOS.
  139. // _forceInterfaceOrientationMask is updated in willChangeStatusBarOrientation, which is called if some presentation controller insists on orientation change.
  140. return [[window rootViewController] supportedInterfaceOrientations] | _forceInterfaceOrientationMask;
  141. }
  142. - (void)application:(UIApplication*)application willChangeStatusBarOrientation:(UIInterfaceOrientation)newStatusBarOrientation duration:(NSTimeInterval)duration
  143. {
  144. // Setting orientation mask which is requiested by iOS: see supportedInterfaceOrientationsForWindow above for details
  145. _forceInterfaceOrientationMask = 1 << newStatusBarOrientation;
  146. }
  147. #endif
  148. #if !PLATFORM_TVOS
  149. - (void)application:(UIApplication*)application didReceiveLocalNotification:(UILocalNotification*)notification
  150. {
  151. AppController_SendNotificationWithArg(kUnityDidReceiveLocalNotification, notification);
  152. UnitySendLocalNotification(notification);
  153. }
  154. #endif
  155. #if UNITY_USES_REMOTE_NOTIFICATIONS
  156. - (void)application:(UIApplication*)application didReceiveRemoteNotification:(NSDictionary*)userInfo
  157. {
  158. AppController_SendNotificationWithArg(kUnityDidReceiveRemoteNotification, userInfo);
  159. UnitySendRemoteNotification(userInfo);
  160. }
  161. - (void)application:(UIApplication*)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData*)deviceToken
  162. {
  163. AppController_SendNotificationWithArg(kUnityDidRegisterForRemoteNotificationsWithDeviceToken, deviceToken);
  164. UnitySendDeviceToken(deviceToken);
  165. }
  166. #if !PLATFORM_TVOS
  167. - (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo fetchCompletionHandler:(void (^)(UIBackgroundFetchResult result))handler
  168. {
  169. AppController_SendNotificationWithArg(kUnityDidReceiveRemoteNotification, userInfo);
  170. UnitySendRemoteNotification(userInfo);
  171. if (handler)
  172. {
  173. handler(UIBackgroundFetchResultNoData);
  174. }
  175. }
  176. #endif
  177. - (void)application:(UIApplication*)application didFailToRegisterForRemoteNotificationsWithError:(NSError*)error
  178. {
  179. AppController_SendNotificationWithArg(kUnityDidFailToRegisterForRemoteNotificationsWithError, error);
  180. UnitySendRemoteNotificationError(error);
  181. // alas people do not check remote notification error through api (which is clunky, i agree) so log here to have at least some visibility
  182. ::printf("\nFailed to register for remote notifications:\n%s\n\n", [[error localizedDescription] UTF8String]);
  183. }
  184. #endif
  185. - (BOOL)application:(UIApplication*)application openURL:(NSURL*)url sourceApplication:(NSString*)sourceApplication annotation:(id)annotation
  186. {
  187. NSMutableArray* keys = [NSMutableArray arrayWithCapacity: 3];
  188. NSMutableArray* values = [NSMutableArray arrayWithCapacity: 3];
  189. #define ADD_ITEM(item) do{ if(item) {[keys addObject:@#item]; [values addObject:item];} }while(0)
  190. ADD_ITEM(url);
  191. ADD_ITEM(sourceApplication);
  192. ADD_ITEM(annotation);
  193. #undef ADD_ITEM
  194. NSDictionary* notifData = [NSDictionary dictionaryWithObjects: values forKeys: keys];
  195. AppController_SendNotificationWithArg(kUnityOnOpenURL, notifData);
  196. // [FitfunSDKManager application:application openURL:url sourceApplication:sourceApplication annotation:annotation];
  197. IOSPlatformSDK * sdk = [IOSPlatformSDK sharedInstance];
  198. [sdk startWithUrl:url];
  199. return YES;
  200. }
  201. - (BOOL)application:(UIApplication*)application willFinishLaunchingWithOptions:(NSDictionary*)launchOptions
  202. {
  203. return YES;
  204. }
  205. - (BOOL)application:(UIApplication*)application didFinishLaunchingWithOptions:(NSDictionary*)launchOptions
  206. {
  207. ::printf("-> applicationDidFinishLaunching()\n");
  208. // send notfications
  209. #if !PLATFORM_TVOS
  210. if (UILocalNotification* notification = [launchOptions objectForKey: UIApplicationLaunchOptionsLocalNotificationKey])
  211. UnitySendLocalNotification(notification);
  212. if ([UIDevice currentDevice].generatesDeviceOrientationNotifications == NO)
  213. [[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications];
  214. #endif
  215. UnityInitApplicationNoGraphics([[[NSBundle mainBundle] bundlePath] UTF8String]);
  216. [self selectRenderingAPI];
  217. [UnityRenderingView InitializeForAPI: self.renderingAPI];
  218. _window = [[UIWindow alloc] initWithFrame: [UIScreen mainScreen].bounds];
  219. _unityView = [self createUnityView];
  220. [DisplayManager Initialize];
  221. _mainDisplay = [DisplayManager Instance].mainDisplay;
  222. [_mainDisplay createWithWindow: _window andView: _unityView];
  223. [self createUI];
  224. [self preStartUnity];
  225. // if you wont use keyboard you may comment it out at save some memory
  226. [KeyboardDelegate Initialize];
  227. #if !PLATFORM_TVOS && DISABLE_TOUCH_DELAYS
  228. for (UIGestureRecognizer *g in _window.gestureRecognizers)
  229. {
  230. g.delaysTouchesBegan = false;
  231. }
  232. #endif
  233. //注册初始化
  234. [[FitfunSDKManager ff_sharedInstance] ff_registerSDK];
  235. // [FitfunSDKManager application:application didFinishLaunchingWithOptions:launchOptions];
  236. return YES;
  237. }
  238. - (void)applicationDidEnterBackground:(UIApplication*)application
  239. {
  240. ::printf("-> applicationDidEnterBackground()\n");
  241. }
  242. - (void)applicationWillEnterForeground:(UIApplication*)application
  243. {
  244. ::printf("-> applicationWillEnterForeground()\n");
  245. // applicationWillEnterForeground: might sometimes arrive *before* actually initing unity (e.g. locking on startup)
  246. if (_unityAppReady)
  247. {
  248. // if we were showing video before going to background - the view size may be changed while we are in background
  249. [GetAppController().unityView recreateRenderingSurfaceIfNeeded];
  250. }
  251. }
  252. - (void)applicationDidBecomeActive:(UIApplication*)application
  253. {
  254. ::printf("-> applicationDidBecomeActive()\n");
  255. [self removeSnapshotView];
  256. if (_unityAppReady)
  257. {
  258. if (UnityIsPaused() && _wasPausedExternal == false)
  259. {
  260. UnityWillResume();
  261. UnityPause(0);
  262. }
  263. if (_wasPausedExternal)
  264. {
  265. if (UnityIsFullScreenPlaying())
  266. TryResumeFullScreenVideo();
  267. }
  268. UnitySetPlayerFocus(1);
  269. }
  270. else if (!_startUnityScheduled)
  271. {
  272. _startUnityScheduled = true;
  273. [self performSelector: @selector(startUnity:) withObject: application afterDelay: 0];
  274. }
  275. _didResignActive = false;
  276. }
  277. - (void)removeSnapshotView
  278. {
  279. // do this on the main queue async so that if we try to create one
  280. // and remove in the same frame, this always happens after in the same queue
  281. dispatch_async(dispatch_get_main_queue(), ^{
  282. if (_snapshotView)
  283. {
  284. [_snapshotView removeFromSuperview];
  285. _snapshotView = nil;
  286. // Make sure that the keyboard input field regains focus after the application becomes active.
  287. [[KeyboardDelegate Instance] becomeFirstResponder];
  288. }
  289. });
  290. }
  291. - (void)applicationWillResignActive:(UIApplication*)application
  292. {
  293. ::printf("-> applicationWillResignActive()\n");
  294. if (_unityAppReady)
  295. {
  296. UnitySetPlayerFocus(0);
  297. _wasPausedExternal = UnityIsPaused();
  298. if (_wasPausedExternal == false)
  299. {
  300. // Pause Unity only if we don't need special background processing
  301. // otherwise batched player loop can be called to run user scripts.
  302. if (!UnityGetUseCustomAppBackgroundBehavior())
  303. {
  304. // Force player to do one more frame, so scripts get a chance to render custom screen for minimized app in task manager.
  305. // NB: UnityWillPause will schedule OnApplicationPause message, which will be sent normally inside repaint (unity player loop)
  306. // NB: We will actually pause after the loop (when calling UnityPause).
  307. UnityWillPause();
  308. [self repaint];
  309. UnityPause(1);
  310. // this is done on the next frame so that
  311. // in the case where unity is paused while going
  312. // into the background and an input is deactivated
  313. // we don't mess with the view hierarchy while taking
  314. // a view snapshot (case 760747).
  315. dispatch_async(dispatch_get_main_queue(), ^{
  316. // if we are active again, we don't need to do this anymore
  317. if (!_didResignActive)
  318. {
  319. return;
  320. }
  321. _snapshotView = [self createSnapshotView];
  322. if (_snapshotView)
  323. [_rootView addSubview: _snapshotView];
  324. });
  325. }
  326. }
  327. }
  328. _didResignActive = true;
  329. }
  330. - (void)applicationDidReceiveMemoryWarning:(UIApplication*)application
  331. {
  332. ::printf("WARNING -> applicationDidReceiveMemoryWarning()\n");
  333. UnityLowMemory();
  334. }
  335. - (void)applicationWillTerminate:(UIApplication*)application
  336. {
  337. ::printf("-> applicationWillTerminate()\n");
  338. Profiler_UninitProfiler();
  339. UnityCleanup();
  340. extern void SensorsCleanup();
  341. SensorsCleanup();
  342. }
  343. @end
  344. void AppController_SendNotification(NSString* name)
  345. {
  346. [[NSNotificationCenter defaultCenter] postNotificationName: name object: GetAppController()];
  347. }
  348. void AppController_SendNotificationWithArg(NSString* name, id arg)
  349. {
  350. [[NSNotificationCenter defaultCenter] postNotificationName: name object: GetAppController() userInfo: arg];
  351. }
  352. void AppController_SendUnityViewControllerNotification(NSString* name)
  353. {
  354. [[NSNotificationCenter defaultCenter] postNotificationName: name object: UnityGetGLViewController()];
  355. }
  356. extern "C" UIWindow* UnityGetMainWindow() {
  357. return GetAppController().mainDisplay.window;
  358. }
  359. extern "C" UIViewController* UnityGetGLViewController() {
  360. return GetAppController().rootViewController;
  361. }
  362. extern "C" UIView* UnityGetGLView() {
  363. return GetAppController().unityView;
  364. }
  365. extern "C" ScreenOrientation UnityCurrentOrientation() { return GetAppController().unityView.contentOrientation; }
  366. bool LogToNSLogHandler(LogType logType, const char* log, va_list list)
  367. {
  368. NSLogv([NSString stringWithUTF8String: log], list);
  369. return true;
  370. }
  371. static void AddNewAPIImplIfNeeded();
  372. // From https://stackoverflow.com/questions/4744826/detecting-if-ios-app-is-run-in-debugger
  373. static bool isDebuggerAttachedToConsole(void)
  374. // Returns true if the current process is being debugged (either
  375. // running under the debugger or has a debugger attached post facto).
  376. {
  377. int junk;
  378. int mib[4];
  379. struct kinfo_proc info;
  380. size_t size;
  381. // Initialize the flags so that, if sysctl fails for some bizarre
  382. // reason, we get a predictable result.
  383. info.kp_proc.p_flag = 0;
  384. // Initialize mib, which tells sysctl the info we want, in this case
  385. // we're looking for information about a specific process ID.
  386. mib[0] = CTL_KERN;
  387. mib[1] = KERN_PROC;
  388. mib[2] = KERN_PROC_PID;
  389. mib[3] = getpid();
  390. // Call sysctl.
  391. size = sizeof(info);
  392. junk = sysctl(mib, sizeof(mib) / sizeof(*mib), &info, &size, NULL, 0);
  393. assert(junk == 0);
  394. // We're being debugged if the P_TRACED flag is set.
  395. return ((info.kp_proc.p_flag & P_TRACED) != 0);
  396. }
  397. void UnityInitTrampoline()
  398. {
  399. #if ENABLE_CRASH_REPORT_SUBMISSION
  400. SubmitCrashReportsAsync();
  401. #endif
  402. InitCrashHandling();
  403. _ios42orNewer = _ios43orNewer = _ios50orNewer = _ios60orNewer = _ios70orNewer = true;
  404. NSString* version = [[UIDevice currentDevice] systemVersion];
  405. #define CHECK_VER(s) [version compare: s options: NSNumericSearch] != NSOrderedAscending
  406. _ios80orNewer = CHECK_VER(@"8.0"), _ios81orNewer = CHECK_VER(@"8.1"), _ios82orNewer = CHECK_VER(@"8.2"), _ios83orNewer = CHECK_VER(@"8.3");
  407. _ios90orNewer = CHECK_VER(@"9.0"), _ios91orNewer = CHECK_VER(@"9.1");
  408. _ios100orNewer = CHECK_VER(@"10.0"), _ios101orNewer = CHECK_VER(@"10.1"), _ios102orNewer = CHECK_VER(@"10.2"), _ios103orNewer = CHECK_VER(@"10.3");
  409. _ios110orNewer = CHECK_VER(@"11.0"), _ios111orNewer = CHECK_VER(@"11.1"), _ios112orNewer = CHECK_VER(@"11.2");
  410. #undef CHECK_VER
  411. AddNewAPIImplIfNeeded();
  412. #if !TARGET_IPHONE_SIMULATOR
  413. // Use NSLog logging if a debugger is not attached, otherwise we write to stdout.
  414. if (!isDebuggerAttachedToConsole())
  415. UnitySetLogEntryHandler(LogToNSLogHandler);
  416. #endif
  417. }
  418. // sometimes apple adds new api with obvious fallback on older ios.
  419. // in that case we simply add these functions ourselves to simplify code
  420. static void AddNewAPIImplIfNeeded()
  421. {
  422. if (![[CADisplayLink class] instancesRespondToSelector: @selector(setPreferredFramesPerSecond:)])
  423. {
  424. IMP CADisplayLink_setPreferredFramesPerSecond_IMP = imp_implementationWithBlock(^void(id _self, NSInteger fps) {
  425. typedef void (*SetFrameIntervalFunc)(id, SEL, NSInteger);
  426. UNITY_OBJC_CALL_ON_SELF(_self, @selector(setFrameInterval:), SetFrameIntervalFunc, (int)(60.0f / fps));
  427. });
  428. class_replaceMethod([CADisplayLink class], @selector(setPreferredFramesPerSecond:), CADisplayLink_setPreferredFramesPerSecond_IMP, CADisplayLink_setPreferredFramesPerSecond_Enc);
  429. }
  430. if (![[UIScreen class] instancesRespondToSelector: @selector(nativeScale)])
  431. {
  432. IMP UIScreen_NativeScale_IMP = imp_implementationWithBlock(^CGFloat(id _self) {
  433. return ((UIScreen*)_self).scale;
  434. });
  435. class_replaceMethod([UIScreen class], @selector(nativeScale), UIScreen_NativeScale_IMP, UIScreen_nativeScale_Enc);
  436. }
  437. if (![[UIScreen class] instancesRespondToSelector: @selector(maximumFramesPerSecond)])
  438. {
  439. IMP UIScreen_MaximumFramesPerSecond_IMP = imp_implementationWithBlock(^NSInteger(id _self) {
  440. return 60;
  441. });
  442. class_replaceMethod([UIScreen class], @selector(maximumFramesPerSecond), UIScreen_MaximumFramesPerSecond_IMP, UIScreen_maximumFramesPerSecond_Enc);
  443. }
  444. if (![[UIView class] instancesRespondToSelector: @selector(safeAreaInsets)])
  445. {
  446. IMP UIView_SafeAreaInsets_IMP = imp_implementationWithBlock(^UIEdgeInsets(id _self) {
  447. return UIEdgeInsetsZero;
  448. });
  449. class_replaceMethod([UIView class], @selector(safeAreaInsets), UIView_SafeAreaInsets_IMP, UIView_safeAreaInsets_Enc);
  450. }
  451. }