Commit 3d031b3b authored by Chris Scott's avatar Chris Scott

Remove Cordova references from BackgroundGeolocation lib. All cordova...

Remove Cordova references from BackgroundGeolocation lib.  All cordova references and callbacks will be handled in CDVBackgroundGeolocation
parent 6dc678e5
......@@ -4,19 +4,16 @@
@interface BackgroundGeolocation : NSObject <CLLocationManagerDelegate>
@property (nonatomic, strong) NSString* syncCallbackId;
@property (nonatomic, strong) NSMutableArray* stationaryRegionListeners;
@property (nonatomic, weak) id <CDVCommandDelegate> commandDelegate;
- (void) configure:(CDVInvokedUrlCommand*)config;
- (void) start:(CDVInvokedUrlCommand*)command;
- (void) stop:(CDVInvokedUrlCommand*)command;
- (void) finish:(CDVInvokedUrlCommand*)command;
- (void) onPaceChange:(CDVInvokedUrlCommand*)command;
- (void) setConfig:(CDVInvokedUrlCommand*)command;
- (void) addStationaryRegionListener:(CDVInvokedUrlCommand*)command;
- (void) getStationaryLocation:(CDVInvokedUrlCommand *)command;
- (void) configure:(NSDictionary*)config;
- (void) start;
- (void) stop;
- (void) finish;
- (void) stopBackgroundTask;
- (void) onPaceChange:(BOOL)value;
- (void) setConfig:(NSDictionary*)command;
- (NSDictionary*) getStationaryLocation;
- (void) onSuspend:(NSNotification *)notification;
- (void) onResume:(NSNotification *)notification;
- (void) onAppTerminate;
......
......@@ -65,7 +65,7 @@
}
@synthesize syncCallbackId, stationaryRegionListeners, commandDelegate;
//@synthesize syncCallbackId, stationaryRegionListeners, commandDelegate;
- (id) init
{
......@@ -102,13 +102,9 @@
return [super init];
}
- (void) configure:(CDVInvokedUrlCommand*)command
- (void) configure:(NSDictionary*)config
{
NSDictionary *config = [command.arguments objectAtIndex:0];
[self applyConfig:config];
self.syncCallbackId = command.callbackId;
[self setConfig:config];
locationManager.activityType = activityType;
locationManager.pausesLocationUpdatesAutomatically = YES;
......@@ -126,7 +122,7 @@
}
}
- (void) applyConfig:(NSDictionary*)config
- (void) setConfig:(NSDictionary*)config
{
if (config[@"debug"]) {
isDebugging = [[config objectForKey:@"debug"] boolValue];
......@@ -192,7 +188,7 @@
/**
* Turn on background geolocation
*/
- (void) start:(CDVInvokedUrlCommand*)command
- (void) start
{
enabled = YES;
UIApplicationState state = [[UIApplication sharedApplication] applicationState];
......@@ -207,7 +203,7 @@
/**
* Turn it off
*/
- (void) stop:(CDVInvokedUrlCommand*)command
- (void) stop
{
[self log: @"- CDVBackgroundGeoLocation stop"];
enabled = NO;
......@@ -225,9 +221,9 @@
* Change pace to moving/stopped
* @param {Boolean} isMoving
*/
- (void) onPaceChange:(CDVInvokedUrlCommand *)command
- (void) onPaceChange:(BOOL)value
{
isMoving = [[command.arguments objectAtIndex: 0] boolValue];
isMoving = value;
[self log: @"- CDVBackgroundGeoLocation onPaceChange %d", isMoving];
UIApplicationState state = [[UIApplication sharedApplication] applicationState];
if (state == UIApplicationStateBackground) {
......@@ -235,18 +231,9 @@
}
}
- (void) setConfig:(CDVInvokedUrlCommand*)command
{
NSDictionary *config = [command.arguments objectAtIndex:0];
[self applyConfig:config];
CDVPluginResult* result = nil;
result = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK];
[self.commandDelegate sendPluginResult:result callbackId:command.callbackId];
}
- (void) addStationaryRegionListener:(CDVInvokedUrlCommand*)command
{
/*
if (self.stationaryRegionListeners == nil) {
self.stationaryRegionListeners = [[NSMutableArray alloc] init];
}
......@@ -254,6 +241,7 @@
if (stationaryRegion) {
[self queue:stationaryLocation type:@"stationary"];
}
*/
}
/**
......@@ -290,7 +278,6 @@
}
}
/**
* toggle passive or aggressive location services
*/
......@@ -514,12 +501,12 @@
// Build a resultset for javascript callback.
NSString *locationType = [data objectForKey:@"location_type"];
if ([locationType isEqualToString:@"stationary"]) {
[self fireStationaryRegionListeners:data];
// Any javascript stationaryRegion event-listeners?
[data setObject:[NSNumber numberWithDouble:stationaryRadius] forKey:@"radius"];
[[NSNotificationCenter defaultCenter] postNotificationName:@"BackgroundGeolocation.stationarylocation" object:data];
//[self fireStationaryRegionListeners:data];
} else if ([locationType isEqualToString:@"current"]) {
CDVPluginResult* result = nil;
result = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsDictionary:data];
[result setKeepCallbackAsBool:YES];
[self.commandDelegate sendPluginResult:result callbackId:self.syncCallbackId];
[[NSNotificationCenter defaultCenter] postNotificationName:@"BackgroundGeolocation.location" object:data];
} else {
[self log: @"- CDVBackgroundGeoLocation#sync could not determine location_type."];
[self stopBackgroundTask];
......@@ -529,48 +516,20 @@
/**
* Called by js to signify the end of a background-geolocation event
*/
-(void) finish:(CDVInvokedUrlCommand*)command
-(void) finish
{
[self log: @"- CDVBackgroundGeoLocation finish"];
[self stopBackgroundTask];
}
- (void) fireStationaryRegionListeners:(NSMutableDictionary*)data
{
[self log: @"- CDVBackgroundGeoLocation#fireStationaryRegionListener"];
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];
}
}
/**
* Fetches current stationaryLocation
*/
- (void) getStationaryLocation:(CDVInvokedUrlCommand *)command
- (NSDictionary*) getStationaryLocation
{
[self log: @"- CDVBackgroundGeoLocation getStationaryLocation"];
// Build a resultset for javascript callback.
CDVPluginResult* result = nil;
if (stationaryLocation) {
NSMutableDictionary *returnInfo = [self locationToHash:stationaryLocation];
result = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsDictionary:returnInfo];
} else {
result = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsBool:NO];
}
[self.commandDelegate sendPluginResult:result callbackId:command.callbackId];
NSDictionary *data = [self locationToHash:stationaryLocation];
return data;
}
- (bool) stationaryRegionContainsLocation:(CLLocation*)location {
......
......@@ -8,6 +8,9 @@
@interface CDVBackgroundGeoLocation : CDVPlugin
@property (nonatomic, strong) NSString* syncCallbackId;
@property (nonatomic, strong) NSMutableArray* stationaryRegionListeners;
- (void) configure:(CDVInvokedUrlCommand*)command;
- (void) start:(CDVInvokedUrlCommand*)command;
- (void) stop:(CDVInvokedUrlCommand*)command;
......
......@@ -8,13 +8,20 @@
@implementation CDVBackgroundGeoLocation {
BackgroundGeolocation *bgGeo;
NSDictionary *config;
}
@synthesize syncCallbackId, stationaryRegionListeners;
- (void)pluginInitialize
{
bgGeo = [[BackgroundGeolocation alloc] init];
bgGeo.commandDelegate = self.commandDelegate;
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(onLocationChanged:) name:@"BackgroundGeolocation.location" object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(onStationaryLocation:) name:@"BackgroundGeolocation.stationarylocation" object:nil];
}
/**
* configure plugin
* @param {String} token
......@@ -24,12 +31,21 @@
*/
- (void) configure:(CDVInvokedUrlCommand*)command
{
[bgGeo configure:command];
self.syncCallbackId = command.callbackId;
config = [command.arguments objectAtIndex:0];
[bgGeo configure:config];
}
- (void) setConfig:(CDVInvokedUrlCommand*)command
{
[bgGeo setConfig:command];
NSDictionary *cfg = [command.arguments objectAtIndex:0];
[bgGeo setConfig:cfg];
CDVPluginResult* result = nil;
result = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK];
[self.commandDelegate sendPluginResult:result callbackId:command.callbackId];
}
/**
......@@ -37,14 +53,23 @@
*/
- (void) start:(CDVInvokedUrlCommand*)command
{
[bgGeo start:command];
[bgGeo start];
CDVPluginResult* result = nil;
result = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK];
[self.commandDelegate sendPluginResult:result callbackId:command.callbackId];
}
/**
* Turn it off
*/
- (void) stop:(CDVInvokedUrlCommand*)command
{
[bgGeo stop:command];
[bgGeo stop];
CDVPluginResult* result = nil;
result = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK];
[self.commandDelegate sendPluginResult:result callbackId:command.callbackId];
}
/**
......@@ -53,7 +78,45 @@
*/
- (void) onPaceChange:(CDVInvokedUrlCommand *)command
{
[bgGeo onPaceChange:command];
BOOL moving = [[command.arguments objectAtIndex: 0] boolValue];
[bgGeo onPaceChange:moving];
CDVPluginResult* result = nil;
result = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK];
[self.commandDelegate sendPluginResult:result callbackId:command.callbackId];
}
/**
* location handler from BackgroundGeolocation
*/
- (void)onLocationChanged:(NSNotification*)notification {
NSDictionary *locationData = notification.object;
CDVPluginResult* result = nil;
result = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsDictionary:locationData];
[result setKeepCallbackAsBool:YES];
[self.commandDelegate sendPluginResult:result callbackId:self.syncCallbackId];
NSLog(@"-------------------------------onLocation %@", locationData);
}
- (void) onStationaryLocation:(NSNotification*)notification
{
NSMutableDictionary *data = notification.object;
NSLog(@"-------------------------------onStationaryLocation %@", data);
if (![self.stationaryRegionListeners count]) {
[bgGeo stopBackgroundTask];
return;
}
CDVPluginResult *result = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsDictionary:data];
[result setKeepCallbackAsBool:YES];
for (NSString *callbackId in self.stationaryRegionListeners)
{
[self.commandDelegate sendPluginResult:result callbackId:callbackId];
}
[bgGeo stopBackgroundTask];
}
/**
......@@ -61,12 +124,19 @@
*/
- (void) getStationaryLocation:(CDVInvokedUrlCommand *)command
{
[bgGeo getStationaryLocation:command];
NSDictionary* location = [bgGeo getStationaryLocation];
CDVPluginResult *result = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsDictionary:location];
result = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK];
[self.commandDelegate sendPluginResult:result callbackId:command.callbackId];
}
- (void) addStationaryRegionListener:(CDVInvokedUrlCommand*)command
{
[bgGeo addStationaryRegionListener:command];
if (self.stationaryRegionListeners == nil) {
self.stationaryRegionListeners = [[NSMutableArray alloc] init];
}
[self.stationaryRegionListeners addObject:command.callbackId];
}
/**
......@@ -74,7 +144,7 @@
*/
-(void) finish:(CDVInvokedUrlCommand*)command
{
[bgGeo finish:command];
[bgGeo finish];
}
/**
* If you don't stopMonitoring when application terminates, the app will be awoken still when a
......
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