Browse Source

Merge pull request #10 from rpopovici/master

call request authorization on main thread
Yonah Forst 7 years ago
parent
commit
e63b23ce20
1 changed files with 17 additions and 12 deletions
  1. 17
    12
      permissions/RNPLocation.m

+ 17
- 12
permissions/RNPLocation.m View File

@@ -41,6 +41,7 @@
41 41
         
42 42
         self.locationManager = [[CLLocationManager alloc] init];
43 43
         self.locationManager.delegate = self;
44
+            
44 45
         if ([type isEqualToString:@"always"]) {
45 46
             [self.locationManager requestAlwaysAuthorization];
46 47
         } else {
@@ -51,18 +52,22 @@
51 52
     }
52 53
 }
53 54
 
54
--(void)locationManager:(CLLocationManager *)manager didChangeAuthorizationStatus:(CLAuthorizationStatus)status {
55
-    if (self.locationManager) {
56
-        self.locationManager.delegate = nil;
57
-        self.locationManager = nil;
58
-    }
59
-    
60
-    if (self.completionHandler) {
61
-        //for some reason, checking permission right away returns denied. need to wait a tiny bit
62
-        dispatch_after(dispatch_time(DISPATCH_TIME_NOW, 0.1 * NSEC_PER_SEC), dispatch_get_main_queue(), ^{
63
-            self.completionHandler([RNPLocation getStatus]);
64
-            self.completionHandler = nil;
65
-        });
55
+-(void)locationManager:(CLLocationManager *)manager didChangeAuthorizationStatus:(CLAuthorizationStatus)status
56
+{
57
+    if (status != kCLAuthorizationStatusNotDetermined) {
58
+        if (self.locationManager) {
59
+            self.locationManager.delegate = nil;
60
+            self.locationManager = nil;
61
+        }
62
+
63
+        if (self.completionHandler) {
64
+            //for some reason, checking permission right away returns denied. need to wait a tiny bit
65
+            dispatch_after(dispatch_time(DISPATCH_TIME_NOW, 0.1 * NSEC_PER_SEC), dispatch_get_main_queue(), ^{
66
+                self.completionHandler([RNPLocation getStatus]);
67
+                self.completionHandler = nil;
68
+            });
69
+        }
66 70
     }
67 71
 }
72
+
68 73
 @end