Procházet zdrojové kódy

Fix location permissions on iOS 13 (#329)

Mathieu Acthernoene před 5 roky
rodič
revize
2f31bf8242

+ 5
- 42
ios/LocationAlways/RNPermissionHandlerLocationAlways.m Zobrazit soubor

@@ -6,8 +6,6 @@
6 6
 @interface RNPermissionHandlerLocationAlways() <CLLocationManagerDelegate>
7 7
 
8 8
 @property (nonatomic, strong) CLLocationManager *locationManager;
9
-@property (nonatomic) bool initialChangeEventFired;
10
-@property (nonatomic) bool isWaitingDidBecomeActive;
11 9
 @property (nonatomic, strong) void (^resolve)(RNPermissionStatus status);
12 10
 @property (nonatomic, strong) void (^reject)(NSError *error);
13 11
 
@@ -51,57 +49,22 @@
51 49
   if (![CLLocationManager locationServicesEnabled] || ![RNPermissions isBackgroundModeEnabled:@"location"]) {
52 50
     return resolve(RNPermissionStatusNotAvailable);
53 51
   }
54
-
55
-  CLAuthorizationStatus status = [CLLocationManager authorizationStatus];
56
-
57
-  if (status == kCLAuthorizationStatusAuthorizedAlways) {
58
-    return resolve(RNPermissionStatusAuthorized);
52
+  if ([CLLocationManager authorizationStatus] != kCLAuthorizationStatusNotDetermined) {
53
+    return [self checkWithResolver:resolve rejecter:reject];
59 54
   }
60 55
 
61 56
   _resolve = resolve;
62 57
   _reject = reject;
63
-  _initialChangeEventFired = false;
64
-  _isWaitingDidBecomeActive = false;
65
-
66
-  if (status == kCLAuthorizationStatusAuthorizedWhenInUse && ![RNPermissions isFlaggedAsRequested:[[self class] handlerUniqueId]]) {
67
-    _isWaitingDidBecomeActive = true;
68
-
69
-    [[NSNotificationCenter defaultCenter] addObserver:self
70
-                                             selector:@selector(UIApplicationDidBecomeActiveNotification:)
71
-                                                 name:UIApplicationDidBecomeActiveNotification object:nil];
72
-  }
73 58
 
74 59
   _locationManager = [CLLocationManager new];
75 60
   [_locationManager setDelegate:self];
76 61
   [_locationManager requestAlwaysAuthorization];
77 62
 }
78 63
 
79
-- (void)onAuthorizationStatus {
80
-  [RNPermissions flagAsRequested:[[self class] handlerUniqueId]];
81
-  [self checkWithResolver:_resolve rejecter:_reject];
82
-
83
-  [_locationManager setDelegate:nil];
84
-  _locationManager = nil;
85
-
86
-  if (_isWaitingDidBecomeActive) {
87
-    [[NSNotificationCenter defaultCenter] removeObserver:self
88
-                                                    name:UIApplicationDidBecomeActiveNotification
89
-                                                  object:nil];
90
-  }
91
-}
92
-
93
-- (void)UIApplicationDidBecomeActiveNotification:(NSNotification *)notification {
94
-  if ([CLLocationManager authorizationStatus] == kCLAuthorizationStatusAuthorizedWhenInUse) {
95
-    [self onAuthorizationStatus];
96
-  }
97
-}
98
-
99 64
 - (void)locationManager:(CLLocationManager *)manager didChangeAuthorizationStatus:(CLAuthorizationStatus)status {
100
-  // @see https://github.com/iosphere/ISHPermissionKit/blob/2.1.2/ISHPermissionKit/Requests/ISHPermissionRequestLocation.m#L127
101
-  if (status != kCLAuthorizationStatusNotDetermined && _initialChangeEventFired) {
102
-    [self onAuthorizationStatus];
103
-  } else {
104
-    _initialChangeEventFired = true;
65
+  if (status != kCLAuthorizationStatusNotDetermined) {
66
+    [_locationManager setDelegate:nil];
67
+    [self checkWithResolver:_resolve rejecter:_reject];
105 68
   }
106 69
 }
107 70
 

+ 3
- 15
ios/LocationWhenInUse/RNPermissionHandlerLocationWhenInUse.m Zobrazit soubor

@@ -5,7 +5,6 @@
5 5
 @interface RNPermissionHandlerLocationWhenInUse() <CLLocationManagerDelegate>
6 6
 
7 7
 @property (nonatomic, strong) CLLocationManager *locationManager;
8
-@property (nonatomic) bool initialChangeEventFired;
9 8
 @property (nonatomic, strong) void (^resolve)(RNPermissionStatus status);
10 9
 @property (nonatomic, strong) void (^reject)(NSError *error);
11 10
 
@@ -45,33 +44,22 @@
45 44
   if (![CLLocationManager locationServicesEnabled]) {
46 45
     return resolve(RNPermissionStatusNotAvailable);
47 46
   }
48
-
49 47
   if ([CLLocationManager authorizationStatus] != kCLAuthorizationStatusNotDetermined) {
50 48
     return [self checkWithResolver:resolve rejecter:reject];
51 49
   }
52 50
 
53 51
   _resolve = resolve;
54 52
   _reject = reject;
55
-  _initialChangeEventFired = false;
56 53
 
57 54
   _locationManager = [CLLocationManager new];
58 55
   [_locationManager setDelegate:self];
59 56
   [_locationManager requestWhenInUseAuthorization];
60 57
 }
61 58
 
62
-- (void)onAuthorizationStatus {
63
-  [self checkWithResolver:_resolve rejecter:_reject];
64
-
65
-  [_locationManager setDelegate:nil];
66
-  _locationManager = nil;
67
-}
68
-
69 59
 - (void)locationManager:(CLLocationManager *)manager didChangeAuthorizationStatus:(CLAuthorizationStatus)status {
70
-  // @see https://github.com/iosphere/ISHPermissionKit/blob/2.1.2/ISHPermissionKit/Requests/ISHPermissionRequestLocation.m#L127
71
-  if (status != kCLAuthorizationStatusNotDetermined && _initialChangeEventFired) {
72
-    [self onAuthorizationStatus];
73
-  } else {
74
-    _initialChangeEventFired = true;
60
+  if (status != kCLAuthorizationStatusNotDetermined) {
61
+    [_locationManager setDelegate:nil];
62
+    [self checkWithResolver:_resolve rejecter:_reject];
75 63
   }
76 64
 }
77 65