From 919e8dae30dcb3d35dbba4c6f2730d178b8f1e9d Mon Sep 17 00:00:00 2001 From: Christian Roring Date: Tue, 20 Sep 2016 12:36:56 +0200 Subject: [PATCH 1/3] feat(BackgroundGeolocation): Update to the latest version --- src/plugins/background-geolocation.ts | 239 ++++++++++++++++++++++---- 1 file changed, 207 insertions(+), 32 deletions(-) diff --git a/src/plugins/background-geolocation.ts b/src/plugins/background-geolocation.ts index 2b281236..dc3d90d6 100644 --- a/src/plugins/background-geolocation.ts +++ b/src/plugins/background-geolocation.ts @@ -1,8 +1,7 @@ -import { Cordova, Plugin } from './plugin'; +import {Cordova, Plugin} from './plugin'; declare var window; - export interface Location { /** @@ -104,6 +103,22 @@ export interface Config { */ stopOnTerminate?: boolean; + /**
 + * ANDROID ONLY
 + * Start background service on device boot.
 + * + * Defaults to false
 + */ + startOnBoot?: boolean; + + /**
 + * ANDROID ONLY
 + * If false location service will not be started in foreground and no notification will be shown. + * + * Defaults to true
 + */ + startForeground?: boolean; + /** * ANDROID, WP8 ONLY * The minimum time interval between location updates in seconds. @@ -131,12 +146,19 @@ export interface Config { */ notificationIconColor?: string; - /** - * ANDROID ONLY - * The filename of a custom notification icon. See android quirks. - * NOTE: Only available for API Level >=21. + /**
 + * ANDROID ONLY
 + * The filename of a custom notification icon. See android quirks.
 + * NOTE: Only available for API Level >=21.
 */ - notificationIcon?: string; + notificationIconLarge?: string; + + /**
 + * ANDROID ONLY
 + * The filename of a custom notification icon. See android quirks.
 + * NOTE: Only available for API Level >=21.
 + */ + notificationIconSmall?: string; /** * ANDROID ONLY @@ -152,6 +174,52 @@ export interface Config { */ activityType?: string; + /**
 + * IOS ONLY
 + * Pauses location updates when app is paused
 + * + * Defaults to true
 + */ + pauseLocationUpdates?: boolean; + + /**
 + * Server url where to send HTTP POST with recorded locations
 + * @see https://github.com/mauron85/cordova-plugin-background-geolocation#http-locations-posting
 + */ + url?: string; + + /**
 + * Server url where to send fail to post locations
 + * @see https://github.com/mauron85/cordova-plugin-background-geolocation#http-locations-posting
 + */ + syncUrl?: string; + + /** + * Specifies how many previously failed locations will be sent to server at once
 + * + * Defaults to 100
 + */ + syncThreshold?: number; + + /**
 + * Optional HTTP headers sent along in HTTP request
 + */ + httpHeaders?: any; + + /** + * IOS ONLY
 + * Switch to less accurate significant changes and region monitory when in background (default) + * + * Defaults to 100
 + */ + saveBatteryOnBackground?: boolean; + + /**
 + * Limit maximum number of locations stored into db
 + * + * Defaults to 10000
 + */ + maxLocations?: number; } /** @@ -208,13 +276,61 @@ export interface Config { }) export class BackgroundGeolocation { + /**
 + * Set location service provider @see https://github.com/mauron85/cordova-plugin-background-geolocation/wiki/Android-providers
 + * + * Possible values: + * ANDROID_DISTANCE_FILTER_PROVIDER: 0,
 + * ANDROID_ACTIVITY_PROVIDER: 1
 + * + * @enum {number}
 + */ + static LocationProvider: { + ANDROID_DISTANCE_FILTER_PROVIDER: number, + ANDROID_ACTIVITY_PROVIDER: number + }; + + /** + * Desired accuracy in meters. Possible values [0, 10, 100, 1000].
 + * The lower the number, the more power devoted to GeoLocation resulting in higher accuracy readings.
 + * 1000 results in lowest power drain and least accurate readings.
 + * + * Possible values: + * HIGH: 0
 + * MEDIUM: 10
 + * LOW: 100
 + * PASSIVE: 1000 + * + * enum {number}
 + */ + static Accuracy: { + HIGH: number, + MEDIUM: number, + LOW: number, + PASSIVE: number + }; + + /**
 + * Used in the switchMode function
 + * + * Possible values: + * BACKGROUND: 0 + * FOREGROUND: 1
 + * + * @enum {number}
 + */ + static Mode: { + BACKGROUND: number, + FOREGROUND: number + }; + /** * Configure the plugin. - * + * * @param {Function} Success callback will be called when background location is determined. * @param {Function} Fail callback to be executed every time a geolocation error occurs. * @param {Object} An object of type Config - * + * * @return Location object, which tries to mimic w3c Coordinates interface. * See http://dev.w3.org/geo/api/spec-source.html#coordinates_interface * Callback to be executed every time a geolocation is recorded in the background. @@ -222,39 +338,42 @@ export class BackgroundGeolocation { @Cordova({ sync: true }) - static configure(callback: Function, errorCallback: Function, options: Config): void { return; } - + static configure(callback: Function, errorCallback: Function, options: Config): void { + return; + } /** * Turn ON the background-geolocation system. * The user will be tracked whenever they suspend the app. */ @Cordova() - static start(): Promise { return; } - + static start(): Promise { + return; + } /** * Turn OFF background-tracking */ @Cordova() - static stop(): Promise { return; } - + static stop(): Promise { + return; + } /** * Inform the native plugin that you're finished, the background-task may be completed * NOTE: IOS, WP only */ @Cordova() - static finish() { } - + static finish() { + } /** * Force the plugin to enter "moving" or "stationary" state * NOTE: IOS, WP only */ @Cordova() - static changePace(isMoving: boolean) { } - + static changePace(isMoving: boolean) { + } /** * Setup configuration @@ -262,14 +381,18 @@ export class BackgroundGeolocation { @Cordova({ callbackOrder: 'reverse' }) - static setConfig(options: Config): Promise { return; } + static setConfig(options: Config): Promise { + return; + } /** * Returns current stationaryLocation if available. null if not * NOTE: IOS, WP only */ @Cordova() - static getStationaryLocation(): Promise { return; } + static getStationaryLocation(): Promise { + return; + } /** * Add a stationary-region listener. Whenever the devices enters "stationary-mode", @@ -277,7 +400,9 @@ export class BackgroundGeolocation { * NOTE: IOS, WP only */ @Cordova() - static onStationary(): Promise { return; } + static onStationary(): Promise { + return; + } /** * Check if location is enabled on the device @@ -285,19 +410,23 @@ export class BackgroundGeolocation { * NOTE: ANDROID only */ @Cordova() - static isLocationEnabled(): Promise { return; } + static isLocationEnabled(): Promise { + return; + } /** * Display app settings to change permissions */ - @Cordova({ sync: true }) - static showAppSettings(): void { } + @Cordova({sync: true}) + static showAppSettings(): void { + } /** * Display device location settings */ - @Cordova({ sync: true }) - static showLocationSettings(): void { } + @Cordova({sync: true}) + static showLocationSettings(): void { + } /** * Method can be used to detect user changes in location services settings. @@ -306,14 +435,17 @@ export class BackgroundGeolocation { * NOTE: ANDROID only */ @Cordova() - static watchLocationMode(): Promise { return; } + static watchLocationMode(): Promise { + return; + } /** * Stop watching for location mode changes. * NOTE: ANDROID only */ @Cordova() - static stopWatchingLocationMode() { } + static stopWatchingLocationMode() { + } /** * Method will return all stored locations. @@ -325,20 +457,63 @@ export class BackgroundGeolocation { * NOTE: ANDROID only */ @Cordova() - static getLocations(): Promise { return; } + static getLocations(): Promise { + return; + } + + /**
 + * Method will return locations, which has not been yet posted to server. NOTE: Locations does contain locationId.
 + */ + @Cordova() + static getValidLocations(): Promise { + return; + } /** * Delete stored location by given locationId. * NOTE: ANDROID only */ @Cordova() - static deleteLocation(locationId: number): Promise { return; } + static deleteLocation(locationId: number): Promise { + return; + } /** * Delete all stored locations. * NOTE: ANDROID only */ @Cordova() - static deleteAllLocations(): Promise { return; } + static deleteAllLocations(): Promise { + return; + } + /** + * Normally plugin will handle switching between BACKGROUND and FOREGROUND mode itself. + * Calling switchMode you can override plugin behavior and force plugin to switch into other mode. + * + * In FOREGROUND mode plugin uses iOS local manager to receive locations and behavior is affected by option.desiredAccuracy and option.distanceFilter. + * In BACKGROUND mode plugin uses significant changes and region monitoring to receive locations and uses option.stationaryRadius only.
 + * + * BackgroundGeolocation.Mode.FOREGROUND + * BackgroundGeolocation.Mode.BACKGROUND
 + * + * NOTE: iOS only + * + * @param {number} See above.
 + */ + @Cordova() + static switchMode(modeId: number): Promise { + return; + } + + /**
 + * Return all logged events. Useful for plugin debugging. Parameter limit limits number of returned entries.
 + * @see https://github.com/mauron85/cordova-plugin-background-geolocation/tree/v2.2.1#debugging for more information.
 + * + * @param {number} Limits the number of entries
 + */ + @Cordova() + static getLogEntries(limit: number): Promise { + return; + } } From 808a75e41c9322de67840b725684be7fcd7de929 Mon Sep 17 00:00:00 2001 From: Christian Roring Date: Tue, 20 Sep 2016 13:07:01 +0200 Subject: [PATCH 2/3] feat(BackgroundGeolocation): Update to the latest version --- src/plugins/background-geolocation.ts | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/src/plugins/background-geolocation.ts b/src/plugins/background-geolocation.ts index dc3d90d6..74e57cd0 100644 --- a/src/plugins/background-geolocation.ts +++ b/src/plugins/background-geolocation.ts @@ -285,9 +285,9 @@ export class BackgroundGeolocation { * * @enum {number}
 */ - static LocationProvider: { - ANDROID_DISTANCE_FILTER_PROVIDER: number, - ANDROID_ACTIVITY_PROVIDER: number + static LocationProvider: any = { + ANDROID_DISTANCE_FILTER_PROVIDER: 0, + ANDROID_ACTIVITY_PROVIDER: 1 }; /** @@ -303,11 +303,11 @@ export class BackgroundGeolocation { * * enum {number}
 */ - static Accuracy: { - HIGH: number, - MEDIUM: number, - LOW: number, - PASSIVE: number + static Accuracy: any = { + HIGH: 0, + MEDIUM: 10, + LOW: 100, + PASSIVE: 1000 }; /**
 @@ -319,9 +319,9 @@ export class BackgroundGeolocation { * * @enum {number}
 */ - static Mode: { - BACKGROUND: number, - FOREGROUND: number + static Mode: any = { + BACKGROUND: 0, + FOREGROUND: 1 }; /** From 31706867c7a0e9ebd01829743df311b1b0749f49 Mon Sep 17 00:00:00 2001 From: Christian Roring Date: Tue, 20 Sep 2016 14:00:57 +0200 Subject: [PATCH 3/3] feat(BackgroundGeolocation): code cleanup --- src/plugins/background-geolocation.ts | 71 +++++++-------------------- 1 file changed, 19 insertions(+), 52 deletions(-) diff --git a/src/plugins/background-geolocation.ts b/src/plugins/background-geolocation.ts index 74e57cd0..0179f14e 100644 --- a/src/plugins/background-geolocation.ts +++ b/src/plugins/background-geolocation.ts @@ -338,42 +338,34 @@ export class BackgroundGeolocation { @Cordova({ sync: true }) - static configure(callback: Function, errorCallback: Function, options: Config): void { - return; - } + static configure(callback: Function, errorCallback: Function, options: Config): void { return; } /** * Turn ON the background-geolocation system. * The user will be tracked whenever they suspend the app. */ @Cordova() - static start(): Promise { - return; - } + static start(): Promise { return; } /** * Turn OFF background-tracking */ @Cordova() - static stop(): Promise { - return; - } + static stop(): Promise { return; } /** * Inform the native plugin that you're finished, the background-task may be completed * NOTE: IOS, WP only */ @Cordova() - static finish() { - } + static finish() { } /** * Force the plugin to enter "moving" or "stationary" state * NOTE: IOS, WP only */ @Cordova() - static changePace(isMoving: boolean) { - } + static changePace(isMoving: boolean) { } /** * Setup configuration @@ -381,18 +373,14 @@ export class BackgroundGeolocation { @Cordova({ callbackOrder: 'reverse' }) - static setConfig(options: Config): Promise { - return; - } + static setConfig(options: Config): Promise { return; } /** * Returns current stationaryLocation if available. null if not * NOTE: IOS, WP only */ @Cordova() - static getStationaryLocation(): Promise { - return; - } + static getStationaryLocation(): Promise { return; } /** * Add a stationary-region listener. Whenever the devices enters "stationary-mode", @@ -400,9 +388,7 @@ export class BackgroundGeolocation { * NOTE: IOS, WP only */ @Cordova() - static onStationary(): Promise { - return; - } + static onStationary(): Promise { return; } /** * Check if location is enabled on the device @@ -410,23 +396,19 @@ export class BackgroundGeolocation { * NOTE: ANDROID only */ @Cordova() - static isLocationEnabled(): Promise { - return; - } + static isLocationEnabled(): Promise { return; } /** * Display app settings to change permissions */ @Cordova({sync: true}) - static showAppSettings(): void { - } + static showAppSettings(): void { } /** * Display device location settings */ @Cordova({sync: true}) - static showLocationSettings(): void { - } + static showLocationSettings(): void { } /** * Method can be used to detect user changes in location services settings. @@ -435,17 +417,14 @@ export class BackgroundGeolocation { * NOTE: ANDROID only */ @Cordova() - static watchLocationMode(): Promise { - return; - } + static watchLocationMode(): Promise { return; } /** * Stop watching for location mode changes. * NOTE: ANDROID only */ @Cordova() - static stopWatchingLocationMode() { - } + static stopWatchingLocationMode() { } /** * Method will return all stored locations. @@ -457,35 +436,27 @@ export class BackgroundGeolocation { * NOTE: ANDROID only */ @Cordova() - static getLocations(): Promise { - return; - } + static getLocations(): Promise { return; } /**
 * Method will return locations, which has not been yet posted to server. NOTE: Locations does contain locationId.
 */ @Cordova() - static getValidLocations(): Promise { - return; - } + static getValidLocations(): Promise { return; } /** * Delete stored location by given locationId. * NOTE: ANDROID only */ @Cordova() - static deleteLocation(locationId: number): Promise { - return; - } + static deleteLocation(locationId: number): Promise { return; } /** * Delete all stored locations. * NOTE: ANDROID only */ @Cordova() - static deleteAllLocations(): Promise { - return; - } + static deleteAllLocations(): Promise { return; } /** * Normally plugin will handle switching between BACKGROUND and FOREGROUND mode itself. @@ -502,9 +473,7 @@ export class BackgroundGeolocation { * @param {number} See above.
 */ @Cordova() - static switchMode(modeId: number): Promise { - return; - } + static switchMode(modeId: number): Promise { return; } /**
 * Return all logged events. Useful for plugin debugging. Parameter limit limits number of returned entries.
 @@ -513,7 +482,5 @@ export class BackgroundGeolocation { * @param {number} Limits the number of entries
 */ @Cordova() - static getLogEntries(limit: number): Promise { - return; - } + static getLogEntries(limit: number): Promise { return; } }