CLLocationManager+RQExtension.m 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. //
  2. // CLLocationManager+RQExtension.m
  3. // jiaPei
  4. //
  5. // Created by 张嵘 on 2020/3/18.
  6. // Copyright © 2020 JCZ. All rights reserved.
  7. //
  8. #import "CLLocationManager+RQExtension.h"
  9. #import <objc/runtime.h>
  10. @implementation CLLocationManager (RQExtension)
  11. static inline void pg_swizzleSelector(Class theClass, SEL originalSelector, SEL swizzledSelector) {
  12. Method originaMethod = class_getInstanceMethod(theClass, originalSelector);
  13. Method swizzledMethod = class_getInstanceMethod(theClass, swizzledSelector);
  14. method_exchangeImplementations(originaMethod, swizzledMethod);
  15. }
  16. + (void)load {
  17. if (9 <= [UIDevice currentDevice].systemVersion.floatValue) {
  18. pg_swizzleSelector(UIDevice.class,
  19. @selector(endGeneratingDeviceOrientationNotifications),
  20. @selector(pgEndGeneratingDeviceOrientationNotifications));
  21. }
  22. }
  23. - (void)pgEndGeneratingDeviceOrientationNotifications {
  24. NSLog(@"swizzledSetAllowsBackgroundLocationUpdates isMainThread:%d", [NSThread isMainThread]);
  25. if (![NSThread isMainThread]) {
  26. dispatch_async(dispatch_get_main_queue(), ^{
  27. [self pgEndGeneratingDeviceOrientationNotifications];
  28. });
  29. return;
  30. }
  31. [self pgEndGeneratingDeviceOrientationNotifications];
  32. }
  33. @end