|
@@ -17,13 +17,14 @@
|
17
|
17
|
|
18
|
18
|
@implementation RNPLocation
|
19
|
19
|
|
20
|
|
-+ (NSString *)getStatus
|
|
20
|
++ (NSString *)getStatusForType:(NSString *)type
|
21
|
21
|
{
|
22
|
22
|
int status = [CLLocationManager authorizationStatus];
|
23
|
23
|
switch (status) {
|
24
|
24
|
case kCLAuthorizationStatusAuthorizedAlways:
|
25
|
|
- case kCLAuthorizationStatusAuthorizedWhenInUse:
|
26
|
25
|
return RNPStatusAuthorized;
|
|
26
|
+ case kCLAuthorizationStatusAuthorizedWhenInUse:
|
|
27
|
+ return [type isEqualToString:@"always"] ? RNPStatusDenied : RNPStatusAuthorized;
|
27
|
28
|
case kCLAuthorizationStatusDenied:
|
28
|
29
|
return RNPStatusDenied;
|
29
|
30
|
case kCLAuthorizationStatusRestricted:
|
|
@@ -35,15 +36,15 @@
|
35
|
36
|
|
36
|
37
|
- (void)request:(NSString*)type completionHandler:(void (^)(NSString *))completionHandler
|
37
|
38
|
{
|
38
|
|
- NSString *status = [RNPLocation getStatus];
|
|
39
|
+ NSString *status = [RNPLocation getStatusForType:nil];
|
39
|
40
|
if (status == RNPStatusUndetermined) {
|
40
|
41
|
self.completionHandler = completionHandler;
|
41
|
|
-
|
|
42
|
+
|
42
|
43
|
if (self.locationManager == nil) {
|
43
|
44
|
self.locationManager = [[CLLocationManager alloc] init];
|
44
|
45
|
self.locationManager.delegate = self;
|
45
|
46
|
}
|
46
|
|
-
|
|
47
|
+
|
47
|
48
|
if ([type isEqualToString:@"always"]) {
|
48
|
49
|
[self.locationManager requestAlwaysAuthorization];
|
49
|
50
|
} else {
|
|
@@ -64,14 +65,14 @@
|
64
|
65
|
self.locationManager.delegate = nil;
|
65
|
66
|
self.locationManager = nil;
|
66
|
67
|
}
|
67
|
|
-
|
|
68
|
+
|
68
|
69
|
if (self.completionHandler) {
|
69
|
70
|
//for some reason, checking permission right away returns denied. need to wait a tiny bit
|
70
|
71
|
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, 0.1 * NSEC_PER_SEC), dispatch_get_main_queue(), ^{
|
71
|
|
- self.completionHandler([RNPLocation getStatus]);
|
|
72
|
+ self.completionHandler([RNPLocation getStatusForType:nil]);
|
72
|
73
|
self.completionHandler = nil;
|
73
|
74
|
});
|
74
|
|
- }
|
|
75
|
+ }
|
75
|
76
|
}
|
76
|
77
|
}
|
77
|
78
|
@end
|