Commit d6319eb3 authored by Chris Scott's avatar Chris Scott

Merge pull request #79 from christocracy/revert-78-trigger-activities

Revert "Trigger activities"
parents 18485ae8 a9f6b579
This diff is collapsed.
...@@ -166,9 +166,37 @@ var app = { ...@@ -166,9 +166,37 @@ var app = {
console.log('BackgroundGeoLocation error'); console.log('BackgroundGeoLocation error');
}; };
// Only ios emits this stationary event
bgGeo.onStationary(function(location, taskId) {
console.log('[js] BackgroundGeoLocation onStationary ' + JSON.stringify(location));
app.setCurrentLocation(location);
var coords = location.coords;
// Center ourself on map
app.onClickHome();
if (!app.stationaryRadius) {
app.stationaryRadius = new google.maps.Circle({
fillColor: '#cc0000',
fillOpacity: 0.4,
strokeOpacity: 0,
map: app.map
});
}
var radius = 50;
var center = new google.maps.LatLng(coords.latitude, coords.longitude);
app.stationaryRadius.setRadius(radius);
app.stationaryRadius.setCenter(center);
bgGeo.finish(taskId);
});
// BackgroundGeoLocation is highly configurable. // BackgroundGeoLocation is highly configurable.
bgGeo.configure(callbackFn, failureFn, { bgGeo.configure(callbackFn, failureFn, {
// Geolocation config debug: true, // <-- enable this hear sounds for background-geolocation life-cycle.
desiredAccuracy: 0, desiredAccuracy: 0,
stationaryRadius: 50, stationaryRadius: 50,
distanceFilter: 50, distanceFilter: 50,
...@@ -178,17 +206,13 @@ var app = { ...@@ -178,17 +206,13 @@ var app = {
fastestLocationUpdateInterval: 5000, fastestLocationUpdateInterval: 5000,
activityRecognitionInterval: 10000, activityRecognitionInterval: 10000,
stopTimeout: 0, stopTimeout: 0,
forceReload: false, // <-- [Android] If the user closes the app **while location-tracking is started** , reboot app (WARNING: possibly distruptive to user)
stopOnTerminate: true, // <-- [Android] Allow the background-service to run headless when user closes the app.
startOnBoot: false, // <-- [Android] Auto start background-service in headless mode when device is powered-up.
activityType: 'AutomotiveNavigation', activityType: 'AutomotiveNavigation',
/**
// Application config * HTTP Feature: set an url to allow the native background service to POST locations to your server
debug: true, // <-- enable this hear sounds for background-geolocation life-cycle. */
forceReloadOnLocationChange: false, // <-- [Android] If the user closes the app **while location-tracking is started** , reboot app when a new location is recorded (WARNING: possibly distruptive to user)
forceReloadOnMotionChange: false, // <-- [Android] If the user closes the app **while location-tracking is started** , reboot app when device changes stationary-state (stationary->moving or vice-versa) --WARNING: possibly distruptive to user)
forceReloadOnGeofence: false, // <-- [Android] If the user closes the app **while location-tracking is started** , reboot app when a geofence crossing occurs --WARNING: possibly distruptive to user)
stopOnTerminate: false, // <-- [Android] Allow the background-service to run headless when user closes the app.
startOnBoot: true, // <-- [Android] Auto start background-service in headless mode when device is powered-up.
// HTTP / SQLite config
url: 'http://posttestserver.com/post.php?dir=cordova-background-geolocation', url: 'http://posttestserver.com/post.php?dir=cordova-background-geolocation',
batchSync: true, // <-- [Default: false] Set true to sync locations to server in a single HTTP request. batchSync: true, // <-- [Default: false] Set true to sync locations to server in a single HTTP request.
autoSync: true, // <-- [Default: true] Set true to sync each location to server as it arrives. autoSync: true, // <-- [Default: true] Set true to sync each location to server as it arrives.
...@@ -201,40 +225,9 @@ var app = { ...@@ -201,40 +225,9 @@ var app = {
} }
}); });
// Listen to motion-state changes (stationary / moving) bgGeo.onGeofence(function(identifier, taskId) {
bgGeo.onMotionChange(function(isMoving, location, taskId) { alert('Enter Geofence: ' + identifier);
console.log('[js] BackgroundGeoLocation stationary-state changed ' + isMoving); console.log('[js] Geofence ENTER: ', identifier, taskId);
console.log('[js] location: ' + JSON.stringify(location));
app.setCurrentLocation(location);
var coords = location.coords;
// Center ourself on map
app.onClickHome();
if (!isMoving) {
if (!app.stationaryRadius) {
app.stationaryRadius = new google.maps.Circle({
fillColor: '#cc0000',
fillOpacity: 0.4,
strokeOpacity: 0,
map: app.map
});
}
var radius = 50;
var center = new google.maps.LatLng(coords.latitude, coords.longitude);
app.stationaryRadius.setRadius(radius);
app.stationaryRadius.setCenter(center);
}
bgGeo.finish(taskId);
});
// Listen to Geofence events.
bgGeo.onGeofence(function(params, taskId) {
console.log('[js] Geofence crossed: ', params.action, params.identifier);
bgGeo.finish(taskId); bgGeo.finish(taskId);
}); });
...@@ -247,8 +240,7 @@ var app = { ...@@ -247,8 +240,7 @@ var app = {
identifier: 'MyGeofence', identifier: 'MyGeofence',
radius: 200, radius: 200,
latitude: e.latLng.lat(), latitude: e.latLng.lat(),
longitude: e.latLng.lng(), longitude: e.latLng.lng()
notifyOnEntry: true
}, function() { }, function() {
app.geofence = new google.maps.Circle({ app.geofence = new google.maps.Circle({
fillColor: '#00cc00', fillColor: '#00cc00',
......
This diff is collapsed.
...@@ -12,20 +12,17 @@ ...@@ -12,20 +12,17 @@
@property (nonatomic, strong) NSString* syncCallbackId; @property (nonatomic, strong) NSString* syncCallbackId;
@property (nonatomic) UIBackgroundTaskIdentifier syncTaskId; @property (nonatomic) UIBackgroundTaskIdentifier syncTaskId;
@property (nonatomic, strong) NSString* locationCallbackId; @property (nonatomic, strong) NSString* locationCallbackId;
@property (nonatomic, strong) NSMutableArray* currentPositionListeners;
@property (nonatomic, strong) NSMutableArray* geofenceListeners; @property (nonatomic, strong) NSMutableArray* geofenceListeners;
@property (nonatomic, strong) NSMutableArray* stationaryRegionListeners; @property (nonatomic, strong) NSMutableArray* stationaryRegionListeners;
@property (nonatomic, strong) NSMutableArray* motionChangeListeners;
- (void) configure:(CDVInvokedUrlCommand*)command; - (void) configure:(CDVInvokedUrlCommand*)command;
- (void) start:(CDVInvokedUrlCommand*)command; - (void) start:(CDVInvokedUrlCommand*)command;
- (void) stop:(CDVInvokedUrlCommand*)command; - (void) stop:(CDVInvokedUrlCommand*)command;
- (void) finish:(CDVInvokedUrlCommand*)command; - (void) finish:(CDVInvokedUrlCommand*)command;
- (void) error:(CDVInvokedUrlCommand*)command; - (void) error:(CDVInvokedUrlCommand*)command;
- (void) changePace:(CDVInvokedUrlCommand*)command; - (void) onPaceChange:(CDVInvokedUrlCommand*)command;
- (void) setConfig:(CDVInvokedUrlCommand*)command; - (void) setConfig:(CDVInvokedUrlCommand*)command;
- (void) addStationaryRegionListener:(CDVInvokedUrlCommand*)command; - (void) addStationaryRegionListener:(CDVInvokedUrlCommand*)command;
- (void) addMotionChangeListener:(CDVInvokedUrlCommand*)command;
- (void) getStationaryLocation:(CDVInvokedUrlCommand *)command; - (void) getStationaryLocation:(CDVInvokedUrlCommand *)command;
- (void) getLocations:(CDVInvokedUrlCommand *)command; - (void) getLocations:(CDVInvokedUrlCommand *)command;
- (void) sync:(CDVInvokedUrlCommand *)command; - (void) sync:(CDVInvokedUrlCommand *)command;
...@@ -35,7 +32,6 @@ ...@@ -35,7 +32,6 @@
- (void) removeGeofence:(CDVInvokedUrlCommand *)command; - (void) removeGeofence:(CDVInvokedUrlCommand *)command;
- (void) getGeofences:(CDVInvokedUrlCommand *)command; - (void) getGeofences:(CDVInvokedUrlCommand *)command;
- (void) onGeofence:(CDVInvokedUrlCommand *)command; - (void) onGeofence:(CDVInvokedUrlCommand *)command;
- (void) getCurrentPosition:(CDVInvokedUrlCommand *)command;
- (void) playSound:(CDVInvokedUrlCommand *)command; - (void) playSound:(CDVInvokedUrlCommand *)command;
@end @end
...@@ -10,17 +10,16 @@ ...@@ -10,17 +10,16 @@
NSDictionary *config; NSDictionary *config;
} }
@synthesize syncCallbackId, syncTaskId, locationCallbackId, geofenceListeners, stationaryRegionListeners, motionChangeListeners, currentPositionListeners; @synthesize syncCallbackId, syncTaskId, locationCallbackId, geofenceListeners, stationaryRegionListeners;
- (void)pluginInitialize - (void)pluginInitialize
{ {
bgGeo = [[TSLocationManager alloc] init]; bgGeo = [[TSLocationManager alloc] init];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(onLocationChanged:) name:@"TSLocationManager.location" object:nil]; [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(onLocationChanged:) name:@"TSLocationManager.location" object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(onMotionChange:) name:@"TSLocationManager.motionchange" object:nil]; [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(onStationaryLocation:) name:@"TSLocationManager.stationary" object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(onEnterGeofence:) name:@"TSLocationManager.geofence" object:nil]; [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(onEnterGeofence:) name:@"TSLocationManager.geofence" object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(onSyncComplete:) name:@"TSLocationManager.sync" object:nil]; [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(onSyncComplete:) name:@"TSLocationManager.sync" object:nil];
} }
/** /**
...@@ -79,10 +78,10 @@ ...@@ -79,10 +78,10 @@
* Change pace to moving/stopped * Change pace to moving/stopped
* @param {Boolean} isMoving * @param {Boolean} isMoving
*/ */
- (void) changePace:(CDVInvokedUrlCommand *)command - (void) onPaceChange:(CDVInvokedUrlCommand *)command
{ {
BOOL moving = [[command.arguments objectAtIndex: 0] boolValue]; BOOL moving = [[command.arguments objectAtIndex: 0] boolValue];
[bgGeo changePace:moving]; [bgGeo onPaceChange:moving];
} }
/** /**
...@@ -91,9 +90,8 @@ ...@@ -91,9 +90,8 @@
- (void)onLocationChanged:(NSNotification*)notification { - (void)onLocationChanged:(NSNotification*)notification {
CLLocation *location = [notification.userInfo objectForKey:@"location"]; CLLocation *location = [notification.userInfo objectForKey:@"location"];
NSDictionary *locationData = [bgGeo locationToDictionary:location];
NSDictionary *params = @{ NSDictionary *params = @{
@"location": locationData, @"location": [bgGeo locationToDictionary:location],
@"taskId": @([bgGeo createBackgroundTask]) @"taskId": @([bgGeo createBackgroundTask])
}; };
CDVPluginResult* result = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsDictionary:params]; CDVPluginResult* result = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsDictionary:params];
...@@ -102,52 +100,18 @@ ...@@ -102,52 +100,18 @@
[self.commandDelegate runInBackground:^{ [self.commandDelegate runInBackground:^{
[self.commandDelegate sendPluginResult:result callbackId:self.locationCallbackId]; [self.commandDelegate sendPluginResult:result callbackId:self.locationCallbackId];
}]; }];
if ([self.currentPositionListeners count]) {
for (NSString *callbackId in self.currentPositionListeners) {
NSDictionary *params = @{
@"location": locationData,
@"taskId": @([bgGeo createBackgroundTask])
};
CDVPluginResult *result = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsDictionary:params];
[result setKeepCallbackAsBool:NO];
[self.commandDelegate runInBackground:^{
[self.commandDelegate sendPluginResult:result callbackId:callbackId];
}];
}
[self.currentPositionListeners removeAllObjects];
}
} }
- (void) onStationaryLocation:(NSNotification*)notification
- (void) onMotionChange:(NSNotification*)notification
{ {
if (![self.stationaryRegionListeners count] && ![self.motionChangeListeners count]) { if (![self.stationaryRegionListeners count]) {
return; return;
} }
BOOL isMoving = [[notification.userInfo objectForKey:@"isMoving"] boolValue]; CLLocation *location = [notification.userInfo objectForKey:@"location"];
CLLocation *location = [notification.userInfo objectForKey:@"location"]; NSDictionary *locationData = [bgGeo locationToDictionary:location];
NSDictionary *locationData = [bgGeo locationToDictionary:location];
// @deprecated stationaryRegionListeners in favour of dual-function motionChangeListeners for (NSString *callbackId in self.stationaryRegionListeners) {
if (!isMoving) {
for (NSString *callbackId in self.stationaryRegionListeners) {
NSLog(@"- CALLBACK: %@", callbackId);
NSDictionary *params = @{
@"isMoving": @(isMoving),
@"location": locationData,
@"taskId": @([bgGeo createBackgroundTask])
};
CDVPluginResult *result = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsDictionary:params];
[result setKeepCallbackAsBool:YES];
[self.commandDelegate runInBackground:^{
[self.commandDelegate sendPluginResult:result callbackId:callbackId];
}];
}
}
for (NSString *callbackId in self.motionChangeListeners) {
NSDictionary *params = @{ NSDictionary *params = @{
@"isMoving": @(isMoving),
@"location": locationData, @"location": locationData,
@"taskId": @([bgGeo createBackgroundTask]) @"taskId": @([bgGeo createBackgroundTask])
}; };
...@@ -156,6 +120,7 @@ ...@@ -156,6 +120,7 @@
[self.commandDelegate runInBackground:^{ [self.commandDelegate runInBackground:^{
[self.commandDelegate sendPluginResult:result callbackId:callbackId]; [self.commandDelegate sendPluginResult:result callbackId:callbackId];
}]; }];
} }
} }
...@@ -184,9 +149,6 @@ ...@@ -184,9 +149,6 @@
- (void) onSyncComplete:(NSNotification*)notification - (void) onSyncComplete:(NSNotification*)notification
{ {
if (syncCallbackId == nil) {
return;
}
NSDictionary *params = @{ NSDictionary *params = @{
@"locations": [notification.userInfo objectForKey:@"locations"], @"locations": [notification.userInfo objectForKey:@"locations"],
@"taskId": @(syncTaskId) @"taskId": @(syncTaskId)
...@@ -255,14 +217,6 @@ ...@@ -255,14 +217,6 @@
[self.stationaryRegionListeners addObject:command.callbackId]; [self.stationaryRegionListeners addObject:command.callbackId];
} }
- (void) addMotionChangeListener:(CDVInvokedUrlCommand*)command
{
if (self.motionChangeListeners == nil) {
self.motionChangeListeners = [[NSMutableArray alloc] init];
}
[self.motionChangeListeners addObject:command.callbackId];
}
- (void) addGeofence:(CDVInvokedUrlCommand*)command - (void) addGeofence:(CDVInvokedUrlCommand*)command
{ {
NSDictionary *cfg = [command.arguments objectAtIndex:0]; NSDictionary *cfg = [command.arguments objectAtIndex:0];
...@@ -316,15 +270,6 @@ ...@@ -316,15 +270,6 @@
[self.geofenceListeners addObject:command.callbackId]; [self.geofenceListeners addObject:command.callbackId];
} }
- (void) getCurrentPosition:(CDVInvokedUrlCommand*)command
{
if (self.currentPositionListeners == nil) {
self.currentPositionListeners = [[NSMutableArray alloc] init];
}
[self.currentPositionListeners addObject:command.callbackId];
[bgGeo updateCurrentPosition];
}
- (void) playSound:(CDVInvokedUrlCommand*)command - (void) playSound:(CDVInvokedUrlCommand*)command
{ {
int soundId = [[command.arguments objectAtIndex:0] integerValue]; int soundId = [[command.arguments objectAtIndex:0] integerValue];
......
...@@ -14,7 +14,7 @@ ...@@ -14,7 +14,7 @@
- (UIBackgroundTaskIdentifier) createBackgroundTask; - (UIBackgroundTaskIdentifier) createBackgroundTask;
- (void) stopBackgroundTask:(UIBackgroundTaskIdentifier)taskId; - (void) stopBackgroundTask:(UIBackgroundTaskIdentifier)taskId;
- (void) error:(UIBackgroundTaskIdentifier)taskId message:(NSString*)message; - (void) error:(UIBackgroundTaskIdentifier)taskId message:(NSString*)message;
- (void) changePace:(BOOL)value; - (void) onPaceChange:(BOOL)value;
- (void) setConfig:(NSDictionary*)command; - (void) setConfig:(NSDictionary*)command;
- (NSDictionary*) getStationaryLocation; - (NSDictionary*) getStationaryLocation;
- (void) onSuspend:(NSNotification *)notification; - (void) onSuspend:(NSNotification *)notification;
...@@ -25,7 +25,6 @@ ...@@ -25,7 +25,6 @@
- (void) addGeofence:(NSString*)identifier radius:(CLLocationDistance)radius latitude:(CLLocationDegrees)latitude longitude:(CLLocationDegrees)longitude notifyOnEntry:(BOOL)notifyOnEntry notifyOnExit:(BOOL)notifyOnExit; - (void) addGeofence:(NSString*)identifier radius:(CLLocationDistance)radius latitude:(CLLocationDegrees)latitude longitude:(CLLocationDegrees)longitude notifyOnEntry:(BOOL)notifyOnEntry notifyOnExit:(BOOL)notifyOnExit;
- (BOOL) removeGeofence:(NSString*)identifier; - (BOOL) removeGeofence:(NSString*)identifier;
- (NSArray*) getGeofences; - (NSArray*) getGeofences;
- (void) updateCurrentPosition;
- (void) playSound:(SystemSoundID)soundId; - (void) playSound:(SystemSoundID)soundId;
@end @end
...@@ -6,7 +6,7 @@ ...@@ -6,7 +6,7 @@
<dict> <dict>
<key>Headers/TSLocationManager.h</key> <key>Headers/TSLocationManager.h</key>
<data> <data>
JKFHIrez0AKQjHebrRIQXFDiIfQ= ++tA66F/FJQ/qMup0fGBER20r9U=
</data> </data>
<key>Info.plist</key> <key>Info.plist</key>
<data> <data>
...@@ -21,7 +21,7 @@ ...@@ -21,7 +21,7 @@
<dict> <dict>
<key>Headers/TSLocationManager.h</key> <key>Headers/TSLocationManager.h</key>
<data> <data>
JKFHIrez0AKQjHebrRIQXFDiIfQ= ++tA66F/FJQ/qMup0fGBER20r9U=
</data> </data>
<key>Modules/module.modulemap</key> <key>Modules/module.modulemap</key>
<data> <data>
......
...@@ -83,7 +83,7 @@ module.exports = { ...@@ -83,7 +83,7 @@ module.exports = {
exec(success || function() {}, exec(success || function() {},
failure || function() {}, failure || function() {},
'BackgroundGeoLocation', 'BackgroundGeoLocation',
'changePace', 'onPaceChange',
[isMoving]); [isMoving]);
}, },
/** /**
...@@ -112,7 +112,6 @@ module.exports = { ...@@ -112,7 +112,6 @@ module.exports = {
}, },
/** /**
* Add a stationary-region listener. Whenever the devices enters "stationary-mode", your #success callback will be executed with #location param containing #radius of region * Add a stationary-region listener. Whenever the devices enters "stationary-mode", your #success callback will be executed with #location param containing #radius of region
* @deprecated in favour of dual-function #onMotionChange
* @param {Function} success * @param {Function} success
* @param {Function} failure [optional] NOT IMPLEMENTED * @param {Function} failure [optional] NOT IMPLEMENTED
*/ */
...@@ -137,35 +136,6 @@ module.exports = { ...@@ -137,35 +136,6 @@ module.exports = {
'addStationaryRegionListener', 'addStationaryRegionListener',
[]); []);
}, },
/**
* Add a movement-state-change listener. Whenever the devices enters "stationary" or "moving" mode, your #success callback will be executed with #location param containing #radius of region
* @param {Function} success
* @param {Function} failure [optional] NOT IMPLEMENTED
*/
onMotionChange: function(success, failure) {
var me = this;
success = success || function(isMoving, location, taskId) {
me.finish(taskId);
};
var callback = function(params) {
var isMoving = params.isMoving;
var location = params.location;
var taskId = params.taskId || 'task-id-undefined';
if (!isMoving) {
me.stationaryLocation = location;
}
me._runBackgroundTask(taskId, function() {
success.call(me, isMoving, location, taskId);
}, failure);
};
exec(callback,
failure || function() {},
'BackgroundGeoLocation',
'addMotionChangeListener',
[]);
},
getLocations: function(success, failure) { getLocations: function(success, failure) {
if (typeof(success) !== 'function') { if (typeof(success) !== 'function') {
throw "BackgroundGeolocation#getLocations requires a success callback"; throw "BackgroundGeolocation#getLocations requires a success callback";
...@@ -293,31 +263,6 @@ module.exports = { ...@@ -293,31 +263,6 @@ module.exports = {
[]); []);
}, },
/** /**
* Fetch the current position
*/
getCurrentPosition: function(success, failure) {
var me = this;
success = success || function(location, taskId) {
me.finish(taskId);
};
var mySuccess = function(params) {
var location = params.location || params;
var taskId = params.taskId || 'task-id-undefined';
// Transform timestamp to Date instance.
if (location.timestamp) {
location.timestamp = new Date(location.timestamp);
}
me._runBackgroundTask(taskId, function() {
success.call(this, location, taskId);
});
}
exec(mySuccess || function() {},
failure || function() {},
'BackgroundGeoLocation',
'getCurrentPosition',
[]);
},
/**
* Play a system sound. This is totally experimental. * Play a system sound. This is totally experimental.
* iOS http://iphonedevwiki.net/index.php/AudioServices * iOS http://iphonedevwiki.net/index.php/AudioServices
* Android: * Android:
......
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