UNPKG

12.4 kBJavaScriptView Raw
1"use strict";
2var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
3 var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4 if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
5 else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
6 return c > 3 && r && Object.defineProperty(target, key, r), r;
7};
8var plugin_1 = require('./plugin');
9/**
10 * @name BackgroundGeolocation
11 * @description
12 * This plugin provides foreground and background geolocation with battery-saving "circular region monitoring" and "stop detection". For
13 * more detail, please see https://github.com/mauron85/cordova-plugin-background-geolocation
14 *
15 * @usage
16 *
17 * ```typescript
18 * import { BackgroundGeolocation } from 'ionic-native';
19 *
20 *
21 * // When device is ready :
22 * platform.ready().then(() => {
23 * // IMPORTANT: BackgroundGeolocation must be called within app.ts and or before Geolocation. Otherwise the platform will not ask you for background tracking permission.
24 *
25 * // BackgroundGeolocation is highly configurable. See platform specific configuration options
26 * let config = {
27 * desiredAccuracy: 10,
28 * stationaryRadius: 20,
29 * distanceFilter: 30,
30 * debug: true, // enable this hear sounds for background-geolocation life-cycle.
31 * stopOnTerminate: false, // enable this to clear background location settings when the app terminates
32 * };
33 *
34 * BackgroundGeolocation.configure((location) => {
35 console.log('[js] BackgroundGeolocation callback: ' + location.latitude + ',' + location.longitude);
36
37 // IMPORTANT: You must execute the finish method here to inform the native plugin that you're finished,
38 // and the background-task may be completed. You must do this regardless if your HTTP request is successful or not.
39 // IF YOU DON'T, ios will CRASH YOUR APP for spending too much time in the background.
40 BackgroundGeolocation.finish(); // FOR IOS ONLY
41
42 * }, (error) => {
43 * console.log('BackgroundGeolocation error');
44 * }, config);
45 *
46 * // Turn ON the background-geolocation system. The user will be tracked whenever they suspend the app.
47 * BackgroundGeolocation.start();
48 * })
49 *
50 * // If you wish to turn OFF background-tracking, call the #stop method.
51 * BackgroundGeolocation.stop();
52 *
53 * ```
54 * @interfaces
55 * BackgroundGeolocationResponse
56 * BackgroundGeolocationConfig
57 */
58var BackgroundGeolocation = (function () {
59 function BackgroundGeolocation() {
60 }
61 /**
62 * Configure the plugin.
63 *
64 * @param options {BackgroundGeolocationConfig} options An object of type Config
65 * @return {Observable<any>}
66 */
67 BackgroundGeolocation.configure = function (options) { return; };
68 /**
69 * Turn ON the background-geolocation system.
70 * The user will be tracked whenever they suspend the app.
71 * @returns {Promise<any>}
72 */
73 BackgroundGeolocation.start = function () { return; };
74 /**
75 * Turn OFF background-tracking
76 * @returns {Promise<any>}
77 */
78 BackgroundGeolocation.stop = function () { return; };
79 /**
80 * Inform the native plugin that you're finished, the background-task may be completed
81 * @returns {Promise<any>}
82 */
83 BackgroundGeolocation.finish = function () { return; };
84 /**
85 * Force the plugin to enter "moving" or "stationary" state
86 * @param isMoving {boolean}
87 * @returns {Promise<any>}
88 */
89 BackgroundGeolocation.changePace = function (isMoving) { return; };
90 /**
91 * Setup configuration
92 * @param options {BackgroundGeolocationConfig}
93 * @returns {Promise<any>}
94 */
95 BackgroundGeolocation.setConfig = function (options) { return; };
96 /**
97 * Returns current stationaryLocation if available. null if not
98 * @returns {Promise<Location>}
99 */
100 BackgroundGeolocation.getStationaryLocation = function () { return; };
101 /**
102 * Add a stationary-region listener. Whenever the devices enters "stationary-mode",
103 * your #success callback will be executed with #location param containing #radius of region
104 * @returns {Promise<any>}
105 */
106 BackgroundGeolocation.onStationary = function () { return; };
107 /**
108 * Check if location is enabled on the device
109 * @returns {Promise<number>} Returns a promise with int argument that takes values 0, 1 (true).
110 */
111 BackgroundGeolocation.isLocationEnabled = function () { return; };
112 /**
113 * Display app settings to change permissions
114 */
115 BackgroundGeolocation.showAppSettings = function () { };
116 /**
117 * Display device location settings
118 */
119 BackgroundGeolocation.showLocationSettings = function () { };
120 /**
121 * Method can be used to detect user changes in location services settings.
122 * If user enable or disable location services then success callback will be executed.
123 * In case or error (SettingNotFoundException) fail callback will be executed.
124 * @returns {Promise<boolean>}
125 */
126 BackgroundGeolocation.watchLocationMode = function () { return; };
127 /**
128 * Stop watching for location mode changes.
129 * @returns {Promise<any>}
130 */
131 BackgroundGeolocation.stopWatchingLocationMode = function () { return; };
132 /**
133 * Method will return all stored locations.
134 * Locations are stored when:
135 * - config.stopOnTerminate is false and main activity was killed
136 * by the system
137 * or
138 * - option.debug is true
139 * @returns {Promise<any>}
140 */
141 BackgroundGeolocation.getLocations = function () { return; };
142 /**
143
144 * Method will return locations, which has not been yet posted to server. NOTE: Locations does contain locationId.
145
146 * @returns {Promise<any>}
147 */
148 BackgroundGeolocation.getValidLocations = function () { return; };
149 /**
150 * Delete stored location by given locationId.
151 * @param locationId {number}
152 * @returns {Promise<any>}
153 */
154 BackgroundGeolocation.deleteLocation = function (locationId) { return; };
155 /**
156 * Delete all stored locations.
157 * @returns {Promise<any>}
158 */
159 BackgroundGeolocation.deleteAllLocations = function () { return; };
160 /**
161 * Normally plugin will handle switching between BACKGROUND and FOREGROUND mode itself.
162 * Calling switchMode you can override plugin behavior and force plugin to switch into other mode.
163 *
164 * In FOREGROUND mode plugin uses iOS local manager to receive locations and behavior is affected by option.desiredAccuracy and option.distanceFilter.
165 * In BACKGROUND mode plugin uses significant changes and region monitoring to receive locations and uses option.stationaryRadius only.
166
167 *
168 * BackgroundGeolocation.Mode.FOREGROUND
169 * BackgroundGeolocation.Mode.BACKGROUND
170
171 **
172 * @param modeId {number}
173 * @returns {Promise<any>}
174 */
175 BackgroundGeolocation.switchMode = function (modeId) { return; };
176 /**
177
178 * Return all logged events. Useful for plugin debugging. Parameter limit limits number of returned entries.
179
180 * @see https://github.com/mauron85/cordova-plugin-background-geolocation/tree/v2.2.1#debugging for more information.
181
182 *
183 * @param limit {number} Limits the number of entries
184
185 * @returns {Promise<any>}
186 */
187 BackgroundGeolocation.getLogEntries = function (limit) { return; };
188 /**
189
190 * Set location service provider @see https://github.com/mauron85/cordova-plugin-background-geolocation/wiki/Android-providers
191
192 *
193 * Possible values:
194 * ANDROID_DISTANCE_FILTER_PROVIDER: 0,
195
196 * ANDROID_ACTIVITY_PROVIDER: 1
197
198 *
199 * @enum {number}
200
201 */
202 BackgroundGeolocation.LocationProvider = {
203 ANDROID_DISTANCE_FILTER_PROVIDER: 0,
204 ANDROID_ACTIVITY_PROVIDER: 1
205 };
206 /**
207 * Desired accuracy in meters. Possible values [0, 10, 100, 1000].
208
209 * The lower the number, the more power devoted to GeoLocation resulting in higher accuracy readings.
210
211 * 1000 results in lowest power drain and least accurate readings.
212
213 *
214 * Possible values:
215 * HIGH: 0
216
217 * MEDIUM: 10
218
219 * LOW: 100
220
221 * PASSIVE: 1000
222 *
223 * enum {number}
224
225 */
226 BackgroundGeolocation.Accuracy = {
227 HIGH: 0,
228 MEDIUM: 10,
229 LOW: 100,
230 PASSIVE: 1000
231 };
232 /**
233
234 * Used in the switchMode function
235
236 *
237 * Possible values:
238 * BACKGROUND: 0
239 * FOREGROUND: 1
240
241 *
242 * @enum {number}
243
244 */
245 BackgroundGeolocation.Mode = {
246 BACKGROUND: 0,
247 FOREGROUND: 1
248 };
249 __decorate([
250 plugin_1.Cordova({
251 callbackOrder: 'reverse',
252 observable: true
253 })
254 ], BackgroundGeolocation, "configure", null);
255 __decorate([
256 plugin_1.Cordova()
257 ], BackgroundGeolocation, "start", null);
258 __decorate([
259 plugin_1.Cordova()
260 ], BackgroundGeolocation, "stop", null);
261 __decorate([
262 plugin_1.Cordova({
263 platforms: ['iOS', 'Windows Phone']
264 })
265 ], BackgroundGeolocation, "finish", null);
266 __decorate([
267 plugin_1.Cordova({
268 platforms: ['iOS', 'Windows Phone']
269 })
270 ], BackgroundGeolocation, "changePace", null);
271 __decorate([
272 plugin_1.Cordova({
273 callbackOrder: 'reverse'
274 })
275 ], BackgroundGeolocation, "setConfig", null);
276 __decorate([
277 plugin_1.Cordova({
278 platforms: ['iOS', 'Windows Phone']
279 })
280 ], BackgroundGeolocation, "getStationaryLocation", null);
281 __decorate([
282 plugin_1.Cordova({
283 platforms: ['iOS', 'Windows Phone']
284 })
285 ], BackgroundGeolocation, "onStationary", null);
286 __decorate([
287 plugin_1.Cordova({
288 platforms: ['Android']
289 })
290 ], BackgroundGeolocation, "isLocationEnabled", null);
291 __decorate([
292 plugin_1.Cordova({ sync: true })
293 ], BackgroundGeolocation, "showAppSettings", null);
294 __decorate([
295 plugin_1.Cordova({ sync: true })
296 ], BackgroundGeolocation, "showLocationSettings", null);
297 __decorate([
298 plugin_1.Cordova({
299 platforms: ['Android']
300 })
301 ], BackgroundGeolocation, "watchLocationMode", null);
302 __decorate([
303 plugin_1.Cordova({
304 platforms: ['Android']
305 })
306 ], BackgroundGeolocation, "stopWatchingLocationMode", null);
307 __decorate([
308 plugin_1.Cordova({
309 platforms: ['Android']
310 })
311 ], BackgroundGeolocation, "getLocations", null);
312 __decorate([
313 plugin_1.Cordova()
314 ], BackgroundGeolocation, "getValidLocations", null);
315 __decorate([
316 plugin_1.Cordova({
317 platforms: ['Android']
318 })
319 ], BackgroundGeolocation, "deleteLocation", null);
320 __decorate([
321 plugin_1.Cordova({
322 platforms: ['Android']
323 })
324 ], BackgroundGeolocation, "deleteAllLocations", null);
325 __decorate([
326 plugin_1.Cordova({
327 platforms: ['iOS']
328 })
329 ], BackgroundGeolocation, "switchMode", null);
330 __decorate([
331 plugin_1.Cordova()
332 ], BackgroundGeolocation, "getLogEntries", null);
333 BackgroundGeolocation = __decorate([
334 plugin_1.Plugin({
335 pluginName: 'BackgroundGeolocation',
336 plugin: 'cordova-plugin-mauron85-background-geolocation',
337 pluginRef: 'backgroundGeolocation',
338 repo: 'https://github.com/mauron85/cordova-plugin-background-geolocation',
339 platforms: ['iOS', 'Android', 'Windows Phone 8']
340 })
341 ], BackgroundGeolocation);
342 return BackgroundGeolocation;
343}());
344exports.BackgroundGeolocation = BackgroundGeolocation;
345//# sourceMappingURL=background-geolocation.js.map
\No newline at end of file