|
@@ -37,32 +37,39 @@
|
|
|
{
|
|
{
|
|
|
NSString *status = [RNPLocation getStatus];
|
|
NSString *status = [RNPLocation getStatus];
|
|
|
if (status == RNPStatusUndetermined) {
|
|
if (status == RNPStatusUndetermined) {
|
|
|
- self.completionHandler = completionHandler;
|
|
|
|
|
-
|
|
|
|
|
- self.locationManager = [[CLLocationManager alloc] init];
|
|
|
|
|
- self.locationManager.delegate = self;
|
|
|
|
|
- if ([type isEqualToString:@"always"]) {
|
|
|
|
|
- [self.locationManager requestAlwaysAuthorization];
|
|
|
|
|
- } else {
|
|
|
|
|
- [self.locationManager requestWhenInUseAuthorization];
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ dispatch_async(dispatch_get_main_queue(), ^(){
|
|
|
|
|
+ self.completionHandler = completionHandler;
|
|
|
|
|
+
|
|
|
|
|
+ self.locationManager = [[CLLocationManager alloc] init];
|
|
|
|
|
+ self.locationManager.delegate = self;
|
|
|
|
|
+
|
|
|
|
|
+ if ([type isEqualToString:@"always"]) {
|
|
|
|
|
+ [self.locationManager requestAlwaysAuthorization];
|
|
|
|
|
+ } else {
|
|
|
|
|
+ [self.locationManager requestWhenInUseAuthorization];
|
|
|
|
|
+ }
|
|
|
|
|
+ });
|
|
|
} else {
|
|
} else {
|
|
|
completionHandler(status);
|
|
completionHandler(status);
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
--(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;
|
|
|
|
|
- });
|
|
|
|
|
|
|
+-(void)locationManager:(CLLocationManager *)manager didChangeAuthorizationStatus:(CLAuthorizationStatus)status
|
|
|
|
|
+{
|
|
|
|
|
+ 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
|
|
@end
|