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 @@
- (void) configure:(CDVInvokedUrlCommand*)command;
- (void) start:(CDVInvokedUrlCommand*)command;
- (void) stop:(CDVInvokedUrlCommand*)command;
- (void) test:(CDVInvokedUrlCommand*)command;
- (void) sync;
- (void) onSuspend:(NSNotification *)notification;
- (void) onResume:(NSNotification *)notification;
......
......@@ -23,8 +23,8 @@
object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(onResume:)
name:UIApplicationWillEnterForegroundNotification
selector:@selector(onResume:)
name:UIApplicationWillEnterForegroundNotification
object:nil];
return self;
}
......@@ -54,6 +54,16 @@
[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
{
NSLog(@"CDVBackgroundGeoLocation suspend");
......@@ -63,7 +73,7 @@
[self.locationManager startMonitoringSignificantLocationChanges];
}
}
-(void) onResume:(NSNotification *) notification
-(void) onResume:(NSNotification *) notification
{
NSLog(@"CDVBackgroundGeoLocation resume");
if (self.enabled) {
......@@ -107,15 +117,15 @@
// Some voodoo.
bgTask = [app beginBackgroundTaskWithExpirationHandler:
^{
^{
[app endBackgroundTask:bgTask];
}];
}];
// Prepare a reusable Request instance. We'll reuse it each time we iterate the queue below.
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:[NSURL URLWithString: self.url]
cachePolicy:NSURLRequestReloadIgnoringLocalCacheData
timeoutInterval:10.0];
cachePolicy:NSURLRequestReloadIgnoringLocalCacheData
timeoutInterval:10.0];
[request setHTTPMethod:@"POST"];
[request setValue:@"application/json" forHTTPHeaderField:@"Accept"];
[request setValue:@"application/json" forHTTPHeaderField:@"Content-Type"];
......@@ -125,7 +135,7 @@
// Iterate the queue.
CLLocation *location;
for (location in self.locationCache) {
for (location in self.locationCache) {
// Build the json-data.
NSString *lat = [NSString stringWithFormat: @"%f", location.coordinate.latitude];
NSString *lng = [NSString stringWithFormat: @"%f", location.coordinate.longitude];
......@@ -133,13 +143,15 @@
NSMutableDictionary *params = [NSMutableDictionary dictionary];
NSMutableDictionary *data = [NSMutableDictionary dictionary];
[params setValue: self.token forKey: @"auth_token"];
[params setValue: @"true" forKey: @"background_geolocation"];
[data setValue: lat forKey: @"latitude"];
[data setValue: lng forKey: @"longitude"];
[data setValue: [location.timestamp descriptionWithLocale:[NSLocale systemLocale]] forKey: @"recorded_at"];
[params setObject:data forKey:@"location"];
NSString *json = [params JSONString];
NSData *requestData = [NSData dataWithBytes:[json UTF8String] length:[json length]];
[request setHTTPBody: requestData];
// Synchronous HTTP request
......
......@@ -47,6 +47,13 @@ module.exports = {
'BackgroundGeoLocation',
'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