summaryrefslogtreecommitdiff
path: root/StoneIsland/plugins/cordova-plugin-geolocation/src/ios/CDVLocation.m
diff options
context:
space:
mode:
Diffstat (limited to 'StoneIsland/plugins/cordova-plugin-geolocation/src/ios/CDVLocation.m')
-rw-r--r--StoneIsland/plugins/cordova-plugin-geolocation/src/ios/CDVLocation.m91
1 files changed, 49 insertions, 42 deletions
diff --git a/StoneIsland/plugins/cordova-plugin-geolocation/src/ios/CDVLocation.m b/StoneIsland/plugins/cordova-plugin-geolocation/src/ios/CDVLocation.m
index e4b34a11..d07a8e9c 100644
--- a/StoneIsland/plugins/cordova-plugin-geolocation/src/ios/CDVLocation.m
+++ b/StoneIsland/plugins/cordova-plugin-geolocation/src/ios/CDVLocation.m
@@ -6,9 +6,9 @@
to you under the Apache License, Version 2.0 (the
"License"); you may not use this file except in compliance
with the License. You may obtain a copy of the License at
-
+
http://www.apache.org/licenses/LICENSE-2.0
-
+
Unless required by applicable law or agreed to in writing,
software distributed under the License is distributed on an
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
@@ -65,7 +65,7 @@
- (BOOL)isAuthorized
{
BOOL authorizationStatusClassPropertyAvailable = [CLLocationManager respondsToSelector:@selector(authorizationStatus)]; // iOS 4.2+
-
+
if (authorizationStatusClassPropertyAvailable) {
NSUInteger authStatus = [CLLocationManager authorizationStatus];
#ifdef __IPHONE_8_0
@@ -73,9 +73,9 @@
return (authStatus == kCLAuthorizationStatusAuthorizedWhenInUse) || (authStatus == kCLAuthorizationStatusAuthorizedAlways) || (authStatus == kCLAuthorizationStatusNotDetermined);
}
#endif
- return (authStatus == kCLAuthorizationStatusAuthorized) || (authStatus == kCLAuthorizationStatusNotDetermined);
+ return (authStatus == kCLAuthorizationStatusAuthorizedAlways) || (authStatus == kCLAuthorizationStatusNotDetermined);
}
-
+
// by default, assume YES (for iOS < 4.2)
return YES;
}
@@ -84,11 +84,9 @@
{
BOOL locationServicesEnabledInstancePropertyAvailable = [self.locationManager respondsToSelector:@selector(locationServicesEnabled)]; // iOS 3.x
BOOL locationServicesEnabledClassPropertyAvailable = [CLLocationManager respondsToSelector:@selector(locationServicesEnabled)]; // iOS 4.x
-
+
if (locationServicesEnabledClassPropertyAvailable) { // iOS 4.x
return [CLLocationManager locationServicesEnabled];
- } else if (locationServicesEnabledInstancePropertyAvailable) { // iOS 2.x, iOS 3.x
- return [(id)self.locationManager locationServicesEnabled];
} else {
return NO;
}
@@ -114,10 +112,10 @@
}
// 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+
@@ -132,7 +130,7 @@
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.
@@ -159,7 +157,7 @@
if (![self isLocationServicesEnabled]) {
return;
}
-
+
[self.locationManager stopUpdatingLocation];
__locationStarted = NO;
__highAccuracyEnabled = NO;
@@ -171,14 +169,16 @@
fromLocation:(CLLocation*)oldLocation
{
CDVLocationData* cData = self.locationData;
-
+
cData.locationInfo = newLocation;
- if (self.locationData.locationCallbacks.count > 0) {
- for (NSString* callbackId in self.locationData.locationCallbacks) {
- [self returnLocationInfo:callbackId andKeepCallback:NO];
+ @synchronized (self.locationData.locationCallbacks) {
+ if (self.locationData.locationCallbacks.count > 0) {
+ for (NSString* callbackId in self.locationData.locationCallbacks) {
+ [self returnLocationInfo:callbackId andKeepCallback:NO];
+ }
+
+ [self.locationData.locationCallbacks removeAllObjects];
}
-
- [self.locationData.locationCallbacks removeAllObjects];
}
if (self.locationData.watchCallbacks.count > 0) {
for (NSString* timerId in self.locationData.watchCallbacks) {
@@ -195,7 +195,7 @@
[self.commandDelegate runInBackground:^{
NSString* callbackId = command.callbackId;
BOOL enableHighAccuracy = [[command argumentAtIndex:0] boolValue];
-
+
if ([self isLocationServicesEnabled] == NO) {
NSMutableDictionary* posError = [NSMutableDictionary dictionaryWithCapacity:2];
[posError setObject:[NSNumber numberWithInt:PERMISSIONDENIED] forKey:@"code"];
@@ -207,14 +207,18 @@
self.locationData = [[CDVLocationData alloc] init];
}
CDVLocationData* lData = self.locationData;
- if (!lData.locationCallbacks) {
- lData.locationCallbacks = [NSMutableArray arrayWithCapacity:1];
+ @synchronized (self.locationData.locationCallbacks) {
+ if (!lData.locationCallbacks) {
+ lData.locationCallbacks = [NSMutableArray arrayWithCapacity:1];
+ }
}
-
+
if (!__locationStarted || (__highAccuracyEnabled != enableHighAccuracy)) {
// add the callbackId into the array so we can call back when get data
- if (callbackId != nil) {
- [lData.locationCallbacks addObject:callbackId];
+ @synchronized (self.locationData.locationCallbacks) {
+ if (callbackId != nil) {
+ [lData.locationCallbacks addObject:callbackId];
+ }
}
// Tell the location manager to start notifying us of heading updates
[self startLocation:enableHighAccuracy];
@@ -230,19 +234,19 @@
NSString* callbackId = command.callbackId;
NSString* timerId = [command argumentAtIndex:0];
BOOL enableHighAccuracy = [[command argumentAtIndex:1] boolValue];
-
+
if (!self.locationData) {
self.locationData = [[CDVLocationData alloc] init];
}
CDVLocationData* lData = self.locationData;
-
+
if (!lData.watchCallbacks) {
lData.watchCallbacks = [NSMutableDictionary dictionaryWithCapacity:1];
}
-
+
// add the callbackId into the dictionary so we can call back whenever get data
[lData.watchCallbacks setObject:callbackId forKey:timerId];
-
+
if ([self isLocationServicesEnabled] == NO) {
NSMutableDictionary* posError = [NSMutableDictionary dictionaryWithCapacity:2];
[posError setObject:[NSNumber numberWithInt:PERMISSIONDENIED] forKey:@"code"];
@@ -260,7 +264,7 @@
- (void)clearWatch:(CDVInvokedUrlCommand*)command
{
NSString* timerId = [command argumentAtIndex:0];
-
+
if (self.locationData && self.locationData.watchCallbacks && [self.locationData.watchCallbacks objectForKey:timerId]) {
[self.locationData.watchCallbacks removeObjectForKey:timerId];
if([self.locationData.watchCallbacks count] == 0) {
@@ -278,7 +282,7 @@
{
CDVPluginResult* result = nil;
CDVLocationData* lData = self.locationData;
-
+
if (lData && !lData.locationInfo) {
// return error
result = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR messageToErrorObject:POSITIONUNAVAILABLE];
@@ -294,7 +298,7 @@
[returnInfo setObject:[NSNumber numberWithDouble:lInfo.altitude] forKey:@"altitude"];
[returnInfo setObject:[NSNumber numberWithDouble:lInfo.coordinate.latitude] forKey:@"latitude"];
[returnInfo setObject:[NSNumber numberWithDouble:lInfo.coordinate.longitude] forKey:@"longitude"];
-
+
result = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsDictionary:returnInfo];
[result setKeepCallbackAsBool:keepCallback];
}
@@ -306,17 +310,20 @@
- (void)returnLocationError:(NSUInteger)errorCode withMessage:(NSString*)message
{
NSMutableDictionary* posError = [NSMutableDictionary dictionaryWithCapacity:2];
-
+
[posError setObject:[NSNumber numberWithUnsignedInteger:errorCode] forKey:@"code"];
[posError setObject:message ? message:@"" forKey:@"message"];
CDVPluginResult* result = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR messageAsDictionary:posError];
-
- for (NSString* callbackId in self.locationData.locationCallbacks) {
- [self.commandDelegate sendPluginResult:result callbackId:callbackId];
+
+
+ @synchronized (self.locationData.locationCallbacks) {
+ for (NSString* callbackId in self.locationData.locationCallbacks) {
+ [self.commandDelegate sendPluginResult:result callbackId:callbackId];
+ }
+
+ [self.locationData.locationCallbacks removeAllObjects];
}
-
- [self.locationData.locationCallbacks removeAllObjects];
-
+
for (NSString* callbackId in self.locationData.watchCallbacks) {
[self.commandDelegate sendPluginResult:result callbackId:callbackId];
}
@@ -325,7 +332,7 @@
- (void)locationManager:(CLLocationManager*)manager didFailWithError:(NSError*)error
{
NSLog(@"locationManager::didFailWithError %@", [error localizedFailureReason]);
-
+
CDVLocationData* lData = self.locationData;
if (lData && __locationStarted) {
// TODO: probably have to once over the various error codes and return one of:
@@ -338,10 +345,10 @@
}
[self returnLocationError:positionError withMessage:[error localizedDescription]];
}
-
+
if (error.code != kCLErrorLocationUnknown) {
- [self.locationManager stopUpdatingLocation];
- __locationStarted = NO;
+ [self.locationManager stopUpdatingLocation];
+ __locationStarted = NO;
}
}