avishekcode closed pull request #87: Update CDVLocation.m
URL: https://github.com/apache/cordova-plugin-geolocation/pull/87
 
 
   

This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:

As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):

diff --git a/src/ios/CDVLocation.m b/src/ios/CDVLocation.m
index 26802d6..df984c4 100644
--- a/src/ios/CDVLocation.m
+++ b/src/ios/CDVLocation.m
@@ -94,61 +94,62 @@ - (BOOL)isLocationServicesEnabled
 
 - (void)startLocation:(BOOL)enableHighAccuracy
 {
-    if (![self isLocationServicesEnabled]) {
-        [self returnLocationError:PERMISSIONDENIED withMessage:@"Location 
services are not enabled."];
-        return;
-    }
-    if (![self isAuthorized]) {
-        NSString* message = nil;
-        BOOL authStatusAvailable = [CLLocationManager 
respondsToSelector:@selector(authorizationStatus)]; // iOS 4.2+
-        if (authStatusAvailable) {
-            NSUInteger code = [CLLocationManager authorizationStatus];
-            if (code == kCLAuthorizationStatusNotDetermined) {
-                // could return POSITION_UNAVAILABLE but need to coordinate 
with other platforms
-                message = @"User undecided on application's use of location 
services.";
-            } else if (code == kCLAuthorizationStatusRestricted) {
-                message = @"Application's use of location services is 
restricted.";
+    [self.commandDelegate runInBackground:^{
+        if (![self isLocationServicesEnabled]) {
+            [self returnLocationError:PERMISSIONDENIED withMessage:@"Location 
services are not enabled."];
+            return;
+        }
+        if (![self isAuthorized]) {
+            NSString* message = nil;
+            BOOL authStatusAvailable = [CLLocationManager 
respondsToSelector:@selector(authorizationStatus)]; // iOS 4.2+
+            if (authStatusAvailable) {
+                NSUInteger code = [CLLocationManager authorizationStatus];
+                if (code == kCLAuthorizationStatusNotDetermined) {
+                    // could return POSITION_UNAVAILABLE but need to 
coordinate with other platforms
+                    message = @"User undecided on application's use of 
location services.";
+                } else if (code == kCLAuthorizationStatusRestricted) {
+                    message = @"Application's use of location services is 
restricted.";
+                }
             }
+            // PERMISSIONDENIED is only PositionError that makes sense when 
authorization denied
+            [self returnLocationError:PERMISSIONDENIED withMessage:message];
+            return;
         }
-        // PERMISSIONDENIED is only PositionError that makes sense when 
authorization denied
-        [self returnLocationError:PERMISSIONDENIED withMessage:message];
-
-        return;
-    }
 
 #ifdef __IPHONE_8_0
-    NSUInteger code = [CLLocationManager authorizationStatus];
-    if (code == kCLAuthorizationStatusNotDetermined && ([self.locationManager 
respondsToSelector:@selector(requestAlwaysAuthorization)] || 
[self.locationManager 
respondsToSelector:@selector(requestWhenInUseAuthorization)])) { //iOS8+
-        __highAccuracyEnabled = enableHighAccuracy;
-        if([[NSBundle mainBundle] 
objectForInfoDictionaryKey:@"NSLocationWhenInUseUsageDescription"]){
-            [self.locationManager requestWhenInUseAuthorization];
-        } else if([[NSBundle mainBundle] 
objectForInfoDictionaryKey:@"NSLocationAlwaysUsageDescription"]) {
-            [self.locationManager  requestAlwaysAuthorization];
-        } else {
-            NSLog(@"[Warning] No NSLocationAlwaysUsageDescription or 
NSLocationWhenInUseUsageDescription key is defined in the Info.plist file.");
+        NSUInteger code = [CLLocationManager authorizationStatus];
+        if (code == kCLAuthorizationStatusNotDetermined && 
([self.locationManager 
respondsToSelector:@selector(requestAlwaysAuthorization)] || 
[self.locationManager 
respondsToSelector:@selector(requestWhenInUseAuthorization)])) { //iOS8+
+            __highAccuracyEnabled = enableHighAccuracy;
+            if([[NSBundle mainBundle] 
objectForInfoDictionaryKey:@"NSLocationWhenInUseUsageDescription"]){
+                [self.locationManager requestWhenInUseAuthorization];
+            } else if([[NSBundle mainBundle] 
objectForInfoDictionaryKey:@"NSLocationAlwaysUsageDescription"]) {
+                [self.locationManager  requestAlwaysAuthorization];
+            } else {
+                NSLog(@"[Warning] No NSLocationAlwaysUsageDescription or 
NSLocationWhenInUseUsageDescription key is defined in the Info.plist file.");
+            }
+            return;
         }
-        return;
-    }
 #endif
 
-    // Tell the location manager to start notifying us of location updates. We
-    // first stop, and then start the updating to ensure we get at least one
-    // update, even if our location did not change.
-    [self.locationManager stopUpdatingLocation];
-    [self.locationManager startUpdatingLocation];
-    __locationStarted = YES;
-    if (enableHighAccuracy) {
-        __highAccuracyEnabled = YES;
-        // Set distance filter to 5 for a high accuracy. Setting it to 
"kCLDistanceFilterNone" could provide a
-        // higher accuracy, but it's also just spamming the callback with 
useless reports which drain the battery.
-        self.locationManager.distanceFilter = 5;
-        // Set desired accuracy to Best.
-        self.locationManager.desiredAccuracy = kCLLocationAccuracyBest;
-    } else {
-        __highAccuracyEnabled = NO;
-        self.locationManager.distanceFilter = 10;
-        self.locationManager.desiredAccuracy = 
kCLLocationAccuracyThreeKilometers;
-    }
+        // Tell the location manager to start notifying us of location 
updates. We
+        // first stop, and then start the updating to ensure we get at least 
one
+        // update, even if our location did not change.
+        [self.locationManager stopUpdatingLocation];
+        [self.locationManager startUpdatingLocation];
+        __locationStarted = YES;
+        if (enableHighAccuracy) {
+            __highAccuracyEnabled = YES;
+            // Set distance filter to 5 for a high accuracy. Setting it to 
"kCLDistanceFilterNone" could provide a
+            // higher accuracy, but it's also just spamming the callback with 
useless reports which drain the battery.
+            self.locationManager.distanceFilter = 5;
+            // Set desired accuracy to Best.
+            self.locationManager.desiredAccuracy = kCLLocationAccuracyBest;
+        } else {
+            __highAccuracyEnabled = NO;
+            self.locationManager.distanceFilter = 10;
+            self.locationManager.desiredAccuracy = 
kCLLocationAccuracyThreeKilometers;
+        }
+    }];
 }
 
 - (void)_stopLocation


 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services

---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscr...@cordova.apache.org
For additional commands, e-mail: commits-h...@cordova.apache.org

Reply via email to