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