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 @@ ...@@ -28,6 +28,7 @@
- (void) resetOdometer:(CDVInvokedUrlCommand *)command; - (void) resetOdometer:(CDVInvokedUrlCommand *)command;
- (void) addGeofence:(CDVInvokedUrlCommand *)command; - (void) addGeofence:(CDVInvokedUrlCommand *)command;
- (void) removeGeofence:(CDVInvokedUrlCommand *)command; - (void) removeGeofence:(CDVInvokedUrlCommand *)command;
- (void) getGeofences:(CDVInvokedUrlCommand *)command;
- (void) onGeofence:(CDVInvokedUrlCommand *)command; - (void) onGeofence:(CDVInvokedUrlCommand *)command;
- (void) playSound:(CDVInvokedUrlCommand *)command; - (void) playSound:(CDVInvokedUrlCommand *)command;
@end @end
......
...@@ -129,11 +129,14 @@ ...@@ -129,11 +129,14 @@
if (![self.geofenceListeners count]) { if (![self.geofenceListeners count]) {
return; return;
} }
NSLog(@"- onEnterGeofence: %@", notification.userInfo);
CLCircularRegion *region = [notification.userInfo objectForKey:@"geofence"]; CLCircularRegion *region = [notification.userInfo objectForKey:@"geofence"];
for (NSString *callbackId in self.stationaryRegionListeners) { for (NSString *callbackId in self.geofenceListeners) {
NSDictionary *params = @{ NSDictionary *params = @{
@"identifier": region.identifier, @"identifier": region.identifier,
@"action": [notification.userInfo objectForKey:@"action"],
@"taskId": @([bgGeo createBackgroundTask]) @"taskId": @([bgGeo createBackgroundTask])
}; };
CDVPluginResult *result = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsDictionary:params]; CDVPluginResult *result = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsDictionary:params];
...@@ -141,7 +144,6 @@ ...@@ -141,7 +144,6 @@
[self.commandDelegate runInBackground:^{ [self.commandDelegate runInBackground:^{
[self.commandDelegate sendPluginResult:result callbackId:callbackId]; [self.commandDelegate sendPluginResult:result callbackId:callbackId];
}]; }];
} }
} }
...@@ -231,6 +233,22 @@ ...@@ -231,6 +233,22 @@
[self.commandDelegate sendPluginResult:result callbackId:command.callbackId]; [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 - (void) onGeofence:(CDVInvokedUrlCommand*)command
{ {
if (self.geofenceListeners == nil) { if (self.geofenceListeners == nil) {
......
...@@ -5,7 +5,7 @@ ...@@ -5,7 +5,7 @@
@interface TSLocationManager : NSObject <CLLocationManagerDelegate> @interface TSLocationManager : NSObject <CLLocationManagerDelegate>
@property (nonatomic) CLLocationDistance odometer; @property (nonatomic) CLLocationDistance odometer;
@property (nonatomic, strong) CLLocationManager* locationManager;
- (void) configure:(NSDictionary*)config; - (void) configure:(NSDictionary*)config;
- (void) start; - (void) start;
- (void) stop; - (void) stop;
...@@ -23,6 +23,7 @@ ...@@ -23,6 +23,7 @@
- (NSDictionary*) locationToDictionary:(CLLocation*)location; - (NSDictionary*) locationToDictionary:(CLLocation*)location;
- (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;
- (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>
0rtf3tEfqeHo6WQSpvbXktE2waw= D1StsS2xjuq9sRvFuNw3O74hUYA=
</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>
0rtf3tEfqeHo6WQSpvbXktE2waw= D1StsS2xjuq9sRvFuNw3O74hUYA=
</data> </data>
<key>Modules/module.modulemap</key> <key>Modules/module.modulemap</key>
<data> <data>
......
...@@ -210,10 +210,10 @@ module.exports = { ...@@ -210,10 +210,10 @@ module.exports = {
} }
var me = this; var me = this;
var mySuccess = function(params) { var mySuccess = function(params) {
var identifier = params.identifier, var taskId = params.taskId || 'task-id-undefined';
taskId = params.taskId || 'task-id-undefined'; delete(params.taskId);
success.call(me, identifier, taskId); success.call(me, params, taskId);
} };
exec(mySuccess, exec(mySuccess,
failure || function() {}, failure || function() {},
'BackgroundGeoLocation', 'BackgroundGeoLocation',
...@@ -221,6 +221,16 @@ module.exports = { ...@@ -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. * Play a system sound. This is totally experimental.
* iOS http://iphonedevwiki.net/index.php/AudioServices * iOS http://iphonedevwiki.net/index.php/AudioServices
* Android: * Android:
...@@ -234,6 +244,7 @@ module.exports = { ...@@ -234,6 +244,7 @@ module.exports = {
'playSound', 'playSound',
[soundId]); [soundId]);
}, },
_setTimestamp: function(rs) { _setTimestamp: function(rs) {
// Transform timestamp to Date instance. // Transform timestamp to Date instance.
if (typeof(rs) === 'object') { 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