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 <AudioToolbox/AudioToolbox.h>
#import <Cordova/CDVCommandDelegate.h>
@interface BackgroundGeolocation : NSObject <CLLocationManagerDelegate>
......
......@@ -6,8 +6,6 @@
//
//
#import "BackgroundGeolocation.h"
#import <Cordova/CDVPlugin.h>
#import <Cordova/CDVJSON.h>
// Debug sounds for bg-geolocation life-cycle events.
// http://iphonedevwiki.net/index.php/AudioServices
......@@ -61,12 +59,8 @@
CLLocationAccuracy desiredAccuracy;
CLActivityType activityType;
BOOL disableElasticity;
}
//@synthesize syncCallbackId, stationaryRegionListeners, commandDelegate;
- (id) init
{
locationManager = [[CLLocationManager alloc] init];
......@@ -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
*/
......@@ -473,12 +454,17 @@
// Create a background-task and delegate to Javascript for syncing location
bgTask = [self createBackgroundTask];
[self.commandDelegate runInBackground:^{
[self runInBackground:^{
[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 can't assume normal network access.
......
......@@ -16,7 +16,6 @@
- (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];
......@@ -96,21 +95,18 @@
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);
NSMutableDictionary *locationData = notification.object;
if (![self.stationaryRegionListeners count]) {
[bgGeo stopBackgroundTask];
return;
}
CDVPluginResult *result = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsDictionary:data];
CDVPluginResult *result = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsDictionary:locationData];
[result setKeepCallbackAsBool:YES];
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