Commit 6539611a authored by Chris Scott's avatar Chris Scott

More de-coupling of core lib from Cordova

parent 3d031b3b
#import <CoreLocation/CoreLocation.h> #import <CoreLocation/CoreLocation.h>
#import <AudioToolbox/AudioToolbox.h> #import <AudioToolbox/AudioToolbox.h>
#import <Cordova/CDVCommandDelegate.h>
@interface BackgroundGeolocation : NSObject <CLLocationManagerDelegate> @interface BackgroundGeolocation : NSObject <CLLocationManagerDelegate>
......
...@@ -6,8 +6,6 @@ ...@@ -6,8 +6,6 @@
// //
// //
#import "BackgroundGeolocation.h" #import "BackgroundGeolocation.h"
#import <Cordova/CDVPlugin.h>
#import <Cordova/CDVJSON.h>
// Debug sounds for bg-geolocation life-cycle events. // Debug sounds for bg-geolocation life-cycle events.
// http://iphonedevwiki.net/index.php/AudioServices // http://iphonedevwiki.net/index.php/AudioServices
...@@ -61,12 +59,8 @@ ...@@ -61,12 +59,8 @@
CLLocationAccuracy desiredAccuracy; CLLocationAccuracy desiredAccuracy;
CLActivityType activityType; CLActivityType activityType;
BOOL disableElasticity; BOOL disableElasticity;
} }
//@synthesize syncCallbackId, stationaryRegionListeners, commandDelegate;
- (id) init - (id) init
{ {
locationManager = [[CLLocationManager alloc] init]; locationManager = [[CLLocationManager alloc] init];
...@@ -231,19 +225,6 @@ ...@@ -231,19 +225,6 @@
} }
} }
- (void) addStationaryRegionListener:(CDVInvokedUrlCommand*)command
{
/*
if (self.stationaryRegionListeners == nil) {
self.stationaryRegionListeners = [[NSMutableArray alloc] init];
}
[self.stationaryRegionListeners addObject:command.callbackId];
if (stationaryRegion) {
[self queue:stationaryLocation type:@"stationary"];
}
*/
}
/** /**
* Suspend. Turn on passive location services * Suspend. Turn on passive location services
*/ */
...@@ -473,12 +454,17 @@ ...@@ -473,12 +454,17 @@
// Create a background-task and delegate to Javascript for syncing location // Create a background-task and delegate to Javascript for syncing location
bgTask = [self createBackgroundTask]; bgTask = [self createBackgroundTask];
[self.commandDelegate runInBackground:^{ [self runInBackground:^{
[self sync:data]; [self sync:data];
}]; }];
} }
} }
- (void)runInBackground:(void (^)())block
{
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), block);
}
/** /**
* 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.
......
...@@ -16,7 +16,6 @@ ...@@ -16,7 +16,6 @@
- (void)pluginInitialize - (void)pluginInitialize
{ {
bgGeo = [[BackgroundGeolocation alloc] init]; 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(onLocationChanged:) name:@"BackgroundGeolocation.location" object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(onStationaryLocation:) name:@"BackgroundGeolocation.stationarylocation" object:nil]; [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(onStationaryLocation:) name:@"BackgroundGeolocation.stationarylocation" object:nil];
...@@ -96,21 +95,18 @@ ...@@ -96,21 +95,18 @@
result = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsDictionary:locationData]; result = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsDictionary:locationData];
[result setKeepCallbackAsBool:YES]; [result setKeepCallbackAsBool:YES];
[self.commandDelegate sendPluginResult:result callbackId:self.syncCallbackId]; [self.commandDelegate sendPluginResult:result callbackId:self.syncCallbackId];
NSLog(@"-------------------------------onLocation %@", locationData);
} }
- (void) onStationaryLocation:(NSNotification*)notification - (void) onStationaryLocation:(NSNotification*)notification
{ {
NSMutableDictionary *data = notification.object; NSMutableDictionary *locationData = notification.object;
NSLog(@"-------------------------------onStationaryLocation %@", data);
if (![self.stationaryRegionListeners count]) { if (![self.stationaryRegionListeners count]) {
[bgGeo stopBackgroundTask]; [bgGeo stopBackgroundTask];
return; return;
} }
CDVPluginResult *result = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsDictionary:data]; CDVPluginResult *result = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsDictionary:locationData];
[result setKeepCallbackAsBool:YES]; [result setKeepCallbackAsBool:YES];
for (NSString *callbackId in self.stationaryRegionListeners) for (NSString *callbackId in self.stationaryRegionListeners)
{ {
......
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