Commit d589111e authored by Chris Scott's avatar Chris Scott

Adding test feature. Combining platform js into single file

parent 697a9b57
...@@ -11,6 +11,7 @@ ...@@ -11,6 +11,7 @@
- (void) configure:(CDVInvokedUrlCommand*)command; - (void) configure:(CDVInvokedUrlCommand*)command;
- (void) start:(CDVInvokedUrlCommand*)command; - (void) start:(CDVInvokedUrlCommand*)command;
- (void) stop:(CDVInvokedUrlCommand*)command; - (void) stop:(CDVInvokedUrlCommand*)command;
- (void) test:(CDVInvokedUrlCommand*)command;
- (void) sync; - (void) sync;
- (void) onSuspend:(NSNotification *)notification; - (void) onSuspend:(NSNotification *)notification;
- (void) onResume:(NSNotification *)notification; - (void) onResume:(NSNotification *)notification;
......
...@@ -54,6 +54,16 @@ ...@@ -54,6 +54,16 @@
[self.locationManager stopMonitoringSignificantLocationChanges]; [self.locationManager stopMonitoringSignificantLocationChanges];
} }
- (void) test:(CDVInvokedUrlCommand*)command
{
NSLog(@"CDVBackgroundGeoLocation test");
[self.locationManager startMonitoringSignificantLocationChanges];
if ([self.locationCache count] > 0){
[self sync];
} else {
NSLog(@"CDVBackgroundGeoLocation could not find a location to sync");
}
}
-(void) onSuspend:(NSNotification *) notification -(void) onSuspend:(NSNotification *) notification
{ {
NSLog(@"CDVBackgroundGeoLocation suspend"); NSLog(@"CDVBackgroundGeoLocation suspend");
...@@ -63,7 +73,7 @@ ...@@ -63,7 +73,7 @@
[self.locationManager startMonitoringSignificantLocationChanges]; [self.locationManager startMonitoringSignificantLocationChanges];
} }
} }
-(void) onResume:(NSNotification *) notification -(void) onResume:(NSNotification *) notification
{ {
NSLog(@"CDVBackgroundGeoLocation resume"); NSLog(@"CDVBackgroundGeoLocation resume");
if (self.enabled) { if (self.enabled) {
...@@ -133,6 +143,8 @@ ...@@ -133,6 +143,8 @@
NSMutableDictionary *params = [NSMutableDictionary dictionary]; NSMutableDictionary *params = [NSMutableDictionary dictionary];
NSMutableDictionary *data = [NSMutableDictionary dictionary]; NSMutableDictionary *data = [NSMutableDictionary dictionary];
[params setValue: self.token forKey: @"auth_token"]; [params setValue: self.token forKey: @"auth_token"];
[params setValue: @"true" forKey: @"background_geolocation"];
[data setValue: lat forKey: @"latitude"]; [data setValue: lat forKey: @"latitude"];
[data setValue: lng forKey: @"longitude"]; [data setValue: lng forKey: @"longitude"];
[data setValue: [location.timestamp descriptionWithLocale:[NSLocale systemLocale]] forKey: @"recorded_at"]; [data setValue: [location.timestamp descriptionWithLocale:[NSLocale systemLocale]] forKey: @"recorded_at"];
......
...@@ -47,6 +47,13 @@ module.exports = { ...@@ -47,6 +47,13 @@ module.exports = {
'BackgroundGeoLocation', 'BackgroundGeoLocation',
'stop', 'stop',
[]); []);
},
test: function(success, failure, config) {
exec(success || function() {},
failure || function() {},
'BackgroundGeoLocation',
'test',
[]);
} }
}; };
/***
* Custom Cordova Background GeoLocation plugin. Uses iOS native API
* @author <chris@transistorsoft.com>
* Largely based upon http://www.mindsizzlers.com/2011/07/ios-background-location/
*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*
*/
var exec = require("cordova/exec");
module.exports = {
configure: function(success, failure, config) {
if (!config.auth_token || !config.url) {
console.log("BackgroundGeoLocation requires an auth_token and url to report to the server");
}
exec(success || function() {},
failure || function() {},
'BackgroundGeoLocation',
'configure',
[config.auth_token, config.url]);
},
start: function(success, failure, config) {
exec(success || function() {},
failure || function() {},
'BackgroundGeoLocation',
'start',
[]);
},
stop: function(success, failure, config) {
exec(success || function() {},
failure || function() {},
'BackgroundGeoLocation',
'stop',
[]);
}
};
/***
* Custom Cordova Background GeoLocation plugin. Uses iOS native API
* @author <chris@transistorsoft.com>
* Largely based upon http://www.mindsizzlers.com/2011/07/ios-background-location/
*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*
*/
var exec = require('cordova/exec');
/**
* Provides access to the vibration mechanism on the device.
*/
module.exports = {
/**
* Configure the native API with our authentication-token and url to POST locations to
* TODO Native plugin assumes the json-structure as required by our rails server
* options:
* auth_token: authentication token
* url: endpoint that we post the locations to, including hostname
*/
configure: function(success, fail, options) {
success = (typeof(success) === 'function') ? success : function() {};
fail = (typeof(fail) === 'function') ? fail : function() {};
if (!options.auth_token || !options.url) {
var msg = "BackgroundGeoLocation requires an auth_token and url to report to the server";
console.log(msg);
fail(msg);
return;
}
return Cordova.exec(success, fail, "BackgroundGeoLocation", "configure", [options.auth_token, options.url]);
},
/**
* Enable background GeoLocation
*/
start: function(success, fail, options) {
options = options || {};
success = (typeof(success) === 'function') ? success : function() {};
fail = (typeof(fail) === 'function') ? fail : function() {};
return Cordova.exec(success, fail, "BackgroundGeoLocation", "start", [options]);
},
/**
* disable background GeoLocation
*/
stop: function(success, fail, options) {
options = options || {};
success = (typeof(success) === 'function') ? success : function() {};
fail = (typeof(fail) === 'function') ? fail : function() {};
return Cordova.exec(success, fail, "BackgroundGeoLocation", "stop", [options]);
}
};
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