Commit ca2caa40 authored by Chris Scott's avatar Chris Scott

Logs. re-arrange methods

parent de8f7ad9
...@@ -144,10 +144,13 @@ ...@@ -144,10 +144,13 @@
- (void) flushQueue - (void) flushQueue
{ {
NSLog(@"- CDVBackgroundGeoLocation#flushQueue, %lu, %d", (unsigned long)[locationQueue count], bgTask == UIBackgroundTaskInvalid);
// Sanity-check the duration of last bgTask: If greater than 30s, kill it. // Sanity-check the duration of last bgTask: If greater than 30s, kill it.
if (bgTask != UIBackgroundTaskInvalid) { if (bgTask != UIBackgroundTaskInvalid) {
if (-[lastBgTaskAt timeIntervalSinceNow] > 30.0) { if (-[lastBgTaskAt timeIntervalSinceNow] > 30.0) {
NSLog(@"- CDVBackgroundGeoLocation#flushQueue has to kill an out-standing background-task!");
if (isDebugging) {
[self notify:@"Outstanding bg-task was force-killed"];
}
[self stopBackgroundTask]; [self stopBackgroundTask];
} }
return; return;
...@@ -457,19 +460,22 @@ ...@@ -457,19 +460,22 @@
} }
} }
[self queue:location type:@"current"]; [self queue:location type:@"current"];
}
// Uh-oh: already a background-task in-effect.
// If we have a bgTask hanging around for 60 seconds, kill it and move on; otherwise, wait a bit longer for the existing bgTask to finish.
/*
if (bgTask != UIBackgroundTaskInvalid) {
NSLog(@"Found existing background-task. Added to Queue");
return;
}
*/
/**
* Calculates distanceFilter by rounding speed to nearest 5 and multiplying by 10. Clamped at 1km max.
*/
-(float) calculateDistanceFilter:(float)speed
{
float newDistanceFilter = distanceFilter;
if (speed < 100) {
// (rounded-speed-to-nearest-5) / 2)^2
// eg 5.2 becomes (5/2)^2
newDistanceFilter = pow((5.0 * floorf(fabsf(speed) / 5.0 + 0.5f)), 2) + distanceFilter;
}
return (newDistanceFilter < 1000) ? newDistanceFilter : 1000;
} }
-(void) queue:(CLLocation*)location type:(id)type -(void) queue:(CLLocation*)location type:(id)type
{ {
NSLog(@"- CDVBackgroundGeoLocation queue %@", type); NSLog(@"- CDVBackgroundGeoLocation queue %@", type);
...@@ -478,6 +484,7 @@ ...@@ -478,6 +484,7 @@
[locationQueue addObject:data]; [locationQueue addObject:data];
[self flushQueue]; [self flushQueue];
} }
-(UIBackgroundTaskIdentifier) createBackgroundTask -(UIBackgroundTaskIdentifier) createBackgroundTask
{ {
lastBgTaskAt = [NSDate date]; lastBgTaskAt = [NSDate date];
...@@ -486,20 +493,6 @@ ...@@ -486,20 +493,6 @@
}]; }];
} }
/**
* Calculates distanceFilter by rounding speed to nearest 5 and multiplying by 10. Clamped at 1km max.
*/
-(float) calculateDistanceFilter:(float)speed
{
float newDistanceFilter = distanceFilter;
if (speed < 100) {
// (rounded-speed-to-nearest-5) / 2)^2
// eg 5.2 becomes (5/2)^2
newDistanceFilter = pow((5.0 * floorf(fabsf(speed) / 5.0 + 0.5f)), 2) + distanceFilter;
}
return (newDistanceFilter < 1000) ? newDistanceFilter : 1000;
}
/** /**
* We are running in the background if this is being executed. * We are running in the background if this is being executed.
* We can't assume normal network access. * We can't assume normal network access.
...@@ -534,6 +527,24 @@ ...@@ -534,6 +527,24 @@
} }
} }
- (void) fireStationaryRegionListeners:(NSMutableDictionary*)data
{
NSLog(@"- CDVBackgroundGeoLocation#fireStationaryRegionListeners: %d", [locationQueue count]);
if (![self.stationaryRegionListeners count]) {
[self stopBackgroundTask];
return;
}
// Any javascript stationaryRegion event-listeners?
[data setObject:[NSNumber numberWithDouble:stationaryRadius] forKey:@"radius"];
CDVPluginResult *result = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsDictionary:data];
[result setKeepCallbackAsBool:YES];
for (NSString *callbackId in self.stationaryRegionListeners)
{
[self.commandDelegate sendPluginResult:result callbackId:callbackId];
}
}
/** /**
* Creates a new circle around user and region-monitors it for exit * Creates a new circle around user and region-monitors it for exit
*/ */
...@@ -563,23 +574,6 @@ ...@@ -563,23 +574,6 @@
locationManager.desiredAccuracy = desiredAccuracy; locationManager.desiredAccuracy = desiredAccuracy;
} }
- (void) fireStationaryRegionListeners:(NSMutableDictionary*)data
{
NSLog(@"- CDVBackgroundGeoLocation#fireStationaryRegionListeners: %d", [locationQueue count]);
if (![self.stationaryRegionListeners count]) {
[self stopBackgroundTask];
return;
}
// Any javascript stationaryRegion event-listeners?
[data setObject:[NSNumber numberWithDouble:stationaryRadius] forKey:@"radius"];
CDVPluginResult *result = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsDictionary:data];
[result setKeepCallbackAsBool:YES];
for (NSString *callbackId in self.stationaryRegionListeners)
{
[self.commandDelegate sendPluginResult:result callbackId:callbackId];
}
}
- (bool) stationaryRegionContainsLocation:(CLLocation*)location { - (bool) stationaryRegionContainsLocation:(CLLocation*)location {
CLCircularRegion *region = [locationManager.monitoredRegions member:stationaryRegion]; CLCircularRegion *region = [locationManager.monitoredRegions member:stationaryRegion];
return ([region containsCoordinate:location.coordinate]) ? YES : NO; return ([region containsCoordinate:location.coordinate]) ? YES : NO;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment