Commit e0c61bd6 authored by Chris Scott's avatar Chris Scott

Added life-cycle sounds for debugging. Turn them on by sending debug: true to...

Added life-cycle sounds for debugging.  Turn them on by sending debug: true to configure method.  also must enable background-audio background-mode manually in XCode.  See defines at top of CDVBackgroundGeoLocation.m for the sound-definitions.
parent 5481b52f
......@@ -6,8 +6,19 @@
#import "CDVLocation.h"
#import "CDVBackgroundGeoLocation.h"
#import <Cordova/CDVJSON.h>
#import <AudioToolbox/AudioToolbox.h>
// Debug sounds for bg-geolocation life-cycle events.
// http://iphonedevwiki.net/index.php/AudioServices
#define exitRegionSound 1005
#define locationSyncSound 1004
#define paceChangeYesSound 1110
#define paceChangeNoSound 1112
#define acquiringLocationSound 1103
#define acquiredLocationSound 1052
@implementation CDVBackgroundGeoLocation {
BOOL isDebugging;
BOOL enabled;
NSString *token;
NSString *url;
......@@ -32,8 +43,6 @@
NSInteger distanceFilter;
NSInteger locationTimeout;
NSInteger desiredAccuracy;
}
- (void)pluginInitialize
......@@ -44,6 +53,7 @@
locationManager.delegate = self;
stationaryLocation = nil;
isDebugging = NO;
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(onSuspend:) name:UIApplicationDidEnterBackgroundNotification object:nil];
......@@ -63,11 +73,12 @@
token = [command.arguments objectAtIndex: 0];
url = [command.arguments objectAtIndex: 1];
// Location filtering.
// Params.
stationaryRadius = [[command.arguments objectAtIndex: 2] intValue];
distanceFilter = [[command.arguments objectAtIndex: 3] intValue];
locationTimeout = [[command.arguments objectAtIndex: 4] intValue];
desiredAccuracy = [[command.arguments objectAtIndex: 5] intValue];
isDebugging = [[command.arguments objectAtIndex: 6] boolValue];
syncCallbackId = command.callbackId;
......@@ -100,6 +111,7 @@
NSLog(@" - stationaryRadius: %ld", (long)stationaryRadius);
NSLog(@" - locationTimeout: %ld", (long)locationTimeout);
NSLog(@" - desiredAccuracy: %ld", (long)desiredAccuracy);
NSLog(@" - debug: %hhd", isDebugging);
}
- (void) setConfig:(CDVInvokedUrlCommand*)command
{
......@@ -143,7 +155,6 @@
{
isMoving = [[command.arguments objectAtIndex: 0] boolValue];
NSLog(@"- CDVBackgroundGeoLocation onPaceChange %hhd", isMoving);
UIApplicationState state = [[UIApplication sharedApplication] applicationState];
if (state == UIApplicationStateBackground) {
[self setPace:isMoving];
......@@ -196,7 +207,7 @@
*/
-(void) onSuspend:(NSNotification *) notification
{
NSLog(@"- CDVBackgroundGeoLocation suspend (enabled? %hhdd", enabled);
NSLog(@"- CDVBackgroundGeoLocation suspend (enabled? %hhd)", enabled);
suspendedAt = [NSDate date];
if (enabled) {
......@@ -242,8 +253,14 @@
if (isAcquiringStationaryLocation) {
NSLog(@"- Acquiring stationary location, accuracy: %f", newLocation.horizontalAccuracy);
if (![self isBestStationaryLocation:newLocation]) {
if (isDebugging) {
AudioServicesPlaySystemSound (acquiringLocationSound);
}
return;
}
if (isDebugging) {
AudioServicesPlaySystemSound (acquiredLocationSound);
}
[locationManager stopUpdatingLocation];
isAcquiringStationaryLocation = NO;
[locationManager startMonitoringSignificantLocationChanges];
......@@ -266,7 +283,7 @@
}
-(BOOL) isBestStationaryLocation:(CLLocation*)location {
stationaryLocationAttempts++;
if (stationaryLocationAttempts == 5) {
if (stationaryLocationAttempts == 7) {
return true;
}
if (stationaryLocation == nil || stationaryLocation.horizontalAccuracy > location.horizontalAccuracy) {
......@@ -286,6 +303,9 @@
-(void) sync:(CLLocation*)location
{
NSLog(@" %f,%f", location.coordinate.latitude, location.coordinate.longitude);
if (isDebugging) {
AudioServicesPlaySystemSound (locationSyncSound);
}
NSMutableDictionary* returnInfo = [NSMutableDictionary dictionaryWithCapacity:8];
NSNumber* timestamp = [NSNumber numberWithDouble:([location.timestamp timeIntervalSince1970] * 1000)];
......@@ -323,6 +343,9 @@
- (void)locationManager:(CLLocationManager *)manager didExitRegion:(CLRegion *)region
{
NSLog(@"- CDVBackgroundGeoLocation exit region");
if (isDebugging) {
AudioServicesPlaySystemSound (exitRegionSound);
}
[self setPace:YES];
}
/**
......@@ -354,6 +377,9 @@
{
NSLog(@"- CDVBackgroundGeoLocation setPace %d, stationaryRegion? %d", value, stationaryRegion!=nil);
isMoving = value;
if (isDebugging) {
AudioServicesPlaySystemSound (isMoving ? paceChangeYesSound : paceChangeNoSound);
}
if (value == YES) {
if (stationaryRegion != nil) {
[locationManager stopMonitoringForRegion:stationaryRegion];
......@@ -369,7 +395,7 @@
isAcquiringStationaryLocation = YES;
stationaryLocationAttempts = 0;
locationManager.distanceFilter = kCLDistanceFilterNone;
locationManager.desiredAccuracy = kCLLocationAccuracyBest;
locationManager.desiredAccuracy = kCLLocationAccuracyBestForNavigation;
[locationManager startUpdatingLocation];
}
}
......@@ -385,7 +411,7 @@
}
stationaryRegion = [[CLCircularRegion alloc] initWithCenter: coord radius:stationaryRadius identifier:@"BackgroundGeoLocation stationary region"];
stationaryRegion.notifyOnExit = YES;
[locationManager startMonitoringForRegion:stationaryRegion];
[locationManager startMonitoringForRegion:stationaryRegion desiredAccuracy:desiredAccuracy];
}
// If you don't stopMonitorying when application terminates, the app will be awoken still when a
......
cordova.define("org.transistorsoft.cordova.background-geolocation.BackgroundGeoLocation", function(require, exports, module) {/***
* Custom Cordova Background GeoLocation plugin. Uses iOS native API
* @author <chris@transistorsoft.com>
* @author <brian@briansamson.com>
* iOS native-side is 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) {
......@@ -31,12 +7,13 @@ module.exports = {
distanceFilter = (config.distanceFilter >= 0) ? config.distanceFilter : 500, // meters
locationTimeout = (config.locationTimeout >= 0) ? config.locationTimeout : 60, // seconds
desiredAccuracy = (config.desiredAccuracy >= 0) ? config.desiredAccuracy : 100; // meters
debug = config.debug || false;
exec(success || function() {},
failure || function() {},
'BackgroundGeoLocation',
'configure',
[authToken, url, stationaryRadius, distanceFilter, locationTimeout, desiredAccuracy]);
[authToken, url, stationaryRadius, distanceFilter, locationTimeout, desiredAccuracy, debug]);
},
start: function(success, failure, config) {
exec(success || function() {},
......@@ -89,4 +66,4 @@ module.exports = {
'getStationaryLocation',
[]);
}
};});
};
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