Commit 6c32002c authored by Chris Scott's avatar Chris Scott

Merge pull request #68 from christocracy/geofencing

Geofencing
parents 188bc039 09cd782c
......@@ -28,6 +28,7 @@
- (void) resetOdometer:(CDVInvokedUrlCommand *)command;
- (void) addGeofence:(CDVInvokedUrlCommand *)command;
- (void) removeGeofence:(CDVInvokedUrlCommand *)command;
- (void) getGeofences:(CDVInvokedUrlCommand *)command;
- (void) onGeofence:(CDVInvokedUrlCommand *)command;
- (void) playSound:(CDVInvokedUrlCommand *)command;
@end
......
......@@ -129,19 +129,21 @@
if (![self.geofenceListeners count]) {
return;
}
NSLog(@"- onEnterGeofence: %@", notification.userInfo);
CLCircularRegion *region = [notification.userInfo objectForKey:@"geofence"];
for (NSString *callbackId in self.stationaryRegionListeners) {
for (NSString *callbackId in self.geofenceListeners) {
NSDictionary *params = @{
@"identifier": region.identifier,
@"action": [notification.userInfo objectForKey:@"action"],
@"taskId": @([bgGeo createBackgroundTask])
};
CDVPluginResult *result = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsDictionary:params];
[result setKeepCallbackAsBool:YES];
[self.commandDelegate runInBackground:^{
[self.commandDelegate sendPluginResult:result callbackId:callbackId];
}];
}];
}
}
......@@ -231,6 +233,22 @@
[self.commandDelegate sendPluginResult:result callbackId:command.callbackId];
}
- (void) getGeofences:(CDVInvokedUrlCommand*)command
{
NSMutableArray *rs = [[NSMutableArray alloc] init];
for (CLRegion *geofence in [bgGeo getGeofences]) {
[rs addObject:@{
@"identifier":geofence.identifier,
@"radius": @(geofence.radius),
@"latitude": @(geofence.center.latitude),
@"longitude": @(geofence.center.longitude)
}];
}
CDVPluginResult *result = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsArray:rs];
[self.commandDelegate sendPluginResult:result callbackId:command.callbackId];
}
- (void) onGeofence:(CDVInvokedUrlCommand*)command
{
if (self.geofenceListeners == nil) {
......
......@@ -5,7 +5,7 @@
@interface TSLocationManager : NSObject <CLLocationManagerDelegate>
@property (nonatomic) CLLocationDistance odometer;
@property (nonatomic, strong) CLLocationManager* locationManager;
- (void) configure:(NSDictionary*)config;
- (void) start;
- (void) stop;
......@@ -23,6 +23,7 @@
- (NSDictionary*) locationToDictionary:(CLLocation*)location;
- (void) addGeofence:(NSString*)identifier radius:(CLLocationDistance)radius latitude:(CLLocationDegrees)latitude longitude:(CLLocationDegrees)longitude notifyOnEntry:(BOOL)notifyOnEntry notifyOnExit:(BOOL)notifyOnExit;
- (BOOL) removeGeofence:(NSString*)identifier;
- (NSArray*) getGeofences;
- (void) playSound:(SystemSoundID)soundId;
@end
......@@ -6,7 +6,7 @@
<dict>
<key>Headers/TSLocationManager.h</key>
<data>
0rtf3tEfqeHo6WQSpvbXktE2waw=
D1StsS2xjuq9sRvFuNw3O74hUYA=
</data>
<key>Info.plist</key>
<data>
......@@ -21,7 +21,7 @@
<dict>
<key>Headers/TSLocationManager.h</key>
<data>
0rtf3tEfqeHo6WQSpvbXktE2waw=
D1StsS2xjuq9sRvFuNw3O74hUYA=
</data>
<key>Modules/module.modulemap</key>
<data>
......
......@@ -210,10 +210,10 @@ module.exports = {
}
var me = this;
var mySuccess = function(params) {
var identifier = params.identifier,
taskId = params.taskId || 'task-id-undefined';
success.call(me, identifier, taskId);
}
var taskId = params.taskId || 'task-id-undefined';
delete(params.taskId);
success.call(me, params, taskId);
};
exec(mySuccess,
failure || function() {},
'BackgroundGeoLocation',
......@@ -221,6 +221,16 @@ module.exports = {
[]);
},
/**
* Fetch a list of all monitored geofences
*/
getGeofences: function(success, failure) {
exec(success || function() {},
failure || function() {},
'BackgroundGeoLocation',
'getGeofences',
[]);
},
/**
* Play a system sound. This is totally experimental.
* iOS http://iphonedevwiki.net/index.php/AudioServices
* Android:
......@@ -234,6 +244,7 @@ module.exports = {
'playSound',
[soundId]);
},
_setTimestamp: function(rs) {
// Transform timestamp to Date instance.
if (typeof(rs) === 'object') {
......
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