Pārlūkot izejas kodu

ignore the first location permission update

Yonah Forst 9 gadi atpakaļ
vecāks
revīzija
c6e762d9cf
1 mainītis faili ar 18 papildinājumiem un 13 dzēšanām
  1. 18 13
      permissions/RNPLocation.m

+ 18 - 13
permissions/RNPLocation.m

@@ -39,8 +39,11 @@
     if (status == RNPStatusUndetermined) {
         self.completionHandler = completionHandler;
         
-        self.locationManager = [[CLLocationManager alloc] init];
-        self.locationManager.delegate = self;
+        if (self.locationManager == nil) {
+            self.locationManager = [[CLLocationManager alloc] init];
+            self.locationManager.delegate = self;
+        }
+        
         if ([type isEqualToString:@"always"]) {
             [self.locationManager requestAlwaysAuthorization];
         } else {
@@ -52,17 +55,19 @@
 }
 
 -(void)locationManager:(CLLocationManager *)manager didChangeAuthorizationStatus:(CLAuthorizationStatus)status {
-    if (self.locationManager) {
-        self.locationManager.delegate = nil;
-        self.locationManager = nil;
-    }
-    
-    if (self.completionHandler) {
-        //for some reason, checking permission right away returns denied. need to wait a tiny bit
-        dispatch_after(dispatch_time(DISPATCH_TIME_NOW, 0.1 * NSEC_PER_SEC), dispatch_get_main_queue(), ^{
-            self.completionHandler([RNPLocation getStatus]);
-            self.completionHandler = nil;
-        });
+    if (status != kCLAuthorizationStatusNotDetermined) {
+        if (self.locationManager) {
+            self.locationManager.delegate = nil;
+            self.locationManager = nil;
+        }
+        
+        if (self.completionHandler) {
+            //for some reason, checking permission right away returns denied. need to wait a tiny bit
+            dispatch_after(dispatch_time(DISPATCH_TIME_NOW, 0.1 * NSEC_PER_SEC), dispatch_get_main_queue(), ^{
+                self.completionHandler([RNPLocation getStatus]);
+                self.completionHandler = nil;
+            });
+        }        
     }
 }
 @end