12345678910111213141516171819202122232425262728293031323334353637 |
- //
- // CLLocationManager+RQExtension.m
- // jiaPei
- //
- // Created by 张嵘 on 2020/3/18.
- // Copyright © 2020 JCZ. All rights reserved.
- //
- #import "CLLocationManager+RQExtension.h"
- #import <objc/runtime.h>
- @implementation CLLocationManager (RQExtension)
- static inline void pg_swizzleSelector(Class theClass, SEL originalSelector, SEL swizzledSelector) {
- Method originaMethod = class_getInstanceMethod(theClass, originalSelector);
- Method swizzledMethod = class_getInstanceMethod(theClass, swizzledSelector);
- method_exchangeImplementations(originaMethod, swizzledMethod);
- }
- + (void)load {
- if (9 <= [UIDevice currentDevice].systemVersion.floatValue) {
- pg_swizzleSelector(UIDevice.class,
- @selector(endGeneratingDeviceOrientationNotifications),
- @selector(pgEndGeneratingDeviceOrientationNotifications));
- }
- }
- - (void)pgEndGeneratingDeviceOrientationNotifications {
- NSLog(@"swizzledSetAllowsBackgroundLocationUpdates isMainThread:%d", [NSThread isMainThread]);
- if (![NSThread isMainThread]) {
- dispatch_async(dispatch_get_main_queue(), ^{
- [self pgEndGeneratingDeviceOrientationNotifications];
- });
- return;
- }
- [self pgEndGeneratingDeviceOrientationNotifications];
- }
- @end
|