@capgo/background-geolocation 8.0.33 → 8.0.35
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +28 -21
- package/android/src/main/java/com/capgo/capacitor_background_geolocation/BackgroundGeolocation.java +30 -14
- package/android/src/main/java/com/capgo/capacitor_background_geolocation/GeofenceBootReceiver.java +3 -0
- package/android/src/main/java/com/capgo/capacitor_background_geolocation/GeofenceStore.java +17 -1
- package/dist/docs.json +25 -5
- package/dist/esm/definitions.d.ts +29 -8
- package/dist/esm/definitions.js.map +1 -1
- package/ios/Sources/CapgoBackgroundGeolocationPlugin/CapgoCapacitorBackgroundGeolocationPlugin.swift +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
# Background Geolocation
|
|
2
|
-
|
|
2
|
+
<a href="https://capgo.app/"><img src="https://capgo.app/readme-banner.svg?repo=Cap-go/capacitor-background-geolocation" alt="Capgo - Instant updates for Capacitor" /></a>
|
|
3
3
|
|
|
4
4
|
<div align="center">
|
|
5
5
|
<h2><a href="https://capgo.app/?ref=plugin_background_geolocation"> ➡️ Get Instant updates for your App with Capgo</a></h2>
|
|
@@ -97,15 +97,13 @@ BackgroundGeolocation.setPlannedRoute({soundFile: "assets/myFile.mp3", route: [[
|
|
|
97
97
|
|
|
98
98
|
## Native geofencing
|
|
99
99
|
|
|
100
|
-
Use native geofencing when you need lightweight location boundaries such as stores, job sites, delivery zones, campuses, or check-in areas. The plugin monitors geofences natively
|
|
100
|
+
Use native geofencing when you need lightweight location boundaries such as stores, job sites, delivery zones, campuses, or check-in areas. The plugin monitors geofences natively and emits JavaScript events while the app is active. Android background delivery is optional and only requested when you opt in.
|
|
101
101
|
|
|
102
102
|
```javascript
|
|
103
103
|
import { BackgroundGeolocation } from "@capgo/background-geolocation";
|
|
104
104
|
|
|
105
|
-
// Geofencing can notify JavaScript while the app is alive
|
|
106
|
-
// transitions natively while the WebView is suspended.
|
|
105
|
+
// Geofencing can notify JavaScript while the app is alive.
|
|
107
106
|
await BackgroundGeolocation.setupGeofencing({
|
|
108
|
-
url: "https://api.example.com/geofences",
|
|
109
107
|
notifyOnEntry: true,
|
|
110
108
|
notifyOnExit: true,
|
|
111
109
|
payload: { userId: "123" }
|
|
@@ -129,13 +127,20 @@ handle.remove();
|
|
|
129
127
|
|
|
130
128
|
### Android background geofence permission
|
|
131
129
|
|
|
132
|
-
The plugin does not add `ACCESS_BACKGROUND_LOCATION` by default
|
|
130
|
+
The plugin does not add `ACCESS_BACKGROUND_LOCATION` by default and does not request it unless you explicitly opt in. Apps that only use foreground location can omit this permission.
|
|
131
|
+
|
|
132
|
+
Opt in only when you need Android geofence transitions while the app is in the background:
|
|
133
133
|
|
|
134
134
|
```xml
|
|
135
135
|
<uses-permission android:name="android.permission.ACCESS_BACKGROUND_LOCATION" />
|
|
136
136
|
```
|
|
137
137
|
|
|
138
|
-
|
|
138
|
+
```javascript
|
|
139
|
+
await BackgroundGeolocation.setupGeofencing({
|
|
140
|
+
url: "https://api.example.com/geofences",
|
|
141
|
+
backgroundLocation: true
|
|
142
|
+
});
|
|
143
|
+
```
|
|
139
144
|
|
|
140
145
|
```javascript
|
|
141
146
|
// If you just want the current location, try something like this. The longer
|
|
@@ -211,7 +216,7 @@ Set the the `android.useLegacyBridge` option to `true` in your Capacitor configu
|
|
|
211
216
|
|
|
212
217
|
On Android 13+, the app needs the `POST_NOTIFICATIONS` runtime permission to show the persistent notification informing the user that their location is being used in the background. This runtime permission is requested after the location permission is granted.
|
|
213
218
|
|
|
214
|
-
For geofencing on Android 10+, the app also needs `ACCESS_BACKGROUND_LOCATION`. Android may require the user to grant this from system settings after foreground location is granted; use `openSettings()` if the permission remains denied.
|
|
219
|
+
For background geofencing on Android 10+, the app also needs `ACCESS_BACKGROUND_LOCATION` and `backgroundLocation: true` in `setupGeofencing()`. Android may require the user to grant this from system settings after foreground location is granted; use `openSettings()` if the permission remains denied. Leave `backgroundLocation` unset or `false` if your app does not have Google Play approval for Android background location.
|
|
215
220
|
|
|
216
221
|
If your app forwards location updates to a server in real time, be aware that after 5 minutes in the background Android will throttle HTTP requests initiated from the WebView. The solution is to use a native HTTP plugin such as [CapacitorHttp](https://capacitorjs.com/docs/apis/http). See https://github.com/capacitor-community/background-geolocation/issues/14.
|
|
217
222
|
|
|
@@ -359,8 +364,9 @@ setupGeofencing(options: GeofenceSetupOptions) => Promise<void>
|
|
|
359
364
|
|
|
360
365
|
Configures native geofence transition handling.
|
|
361
366
|
|
|
362
|
-
Call this before adding geofences when you need
|
|
363
|
-
or
|
|
367
|
+
Call this before adding geofences when you need default entry/exit settings
|
|
368
|
+
or native background POSTs. Android background POSTs require
|
|
369
|
+
`backgroundLocation: true`.
|
|
364
370
|
|
|
365
371
|
| Param | Type | Description |
|
|
366
372
|
| ------------- | --------------------------------------------------------------------- | ---------------------------------- |
|
|
@@ -546,17 +552,18 @@ Extends the standard Error with optional error codes.
|
|
|
546
552
|
|
|
547
553
|
Options for configuring native geofence transition handling.
|
|
548
554
|
|
|
549
|
-
When `url` is provided, native
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
| Prop | Type | Description
|
|
554
|
-
| ------------------------ | ---------------------------------------------------------------- |
|
|
555
|
-
| **`url`** | <code>string</code> | Endpoint that receives geofence transition payloads.
|
|
556
|
-
| **`notifyOnEntry`** | <code>boolean</code> | Whether entry transitions should be monitored.
|
|
557
|
-
| **`notifyOnExit`** | <code>boolean</code> | Whether exit transitions should be monitored.
|
|
558
|
-
| **`payload`** | <code><a href="#record">Record</a><string, unknown></code> | Base JSON payload merged into every native transition POST and listener event.
|
|
559
|
-
| **`requestPermissions`** | <code>boolean</code> | Whether the plugin should request the native location permission needed for geofencing. iOS geofencing needs Always location authorization. Android
|
|
555
|
+
When `url` is provided, native code can send a JSON `POST` whenever a
|
|
556
|
+
monitored region is entered or exited. Android background POST delivery
|
|
557
|
+
requires `backgroundLocation: true`.
|
|
558
|
+
|
|
559
|
+
| Prop | Type | Description | Default | Since |
|
|
560
|
+
| ------------------------ | ---------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | ------------------ | ------ |
|
|
561
|
+
| **`url`** | <code>string</code> | Endpoint that receives geofence transition payloads. On Android, native background POST delivery requires `backgroundLocation: true`. | | 8.0.30 |
|
|
562
|
+
| **`notifyOnEntry`** | <code>boolean</code> | Whether entry transitions should be monitored. | <code>true</code> | 8.0.30 |
|
|
563
|
+
| **`notifyOnExit`** | <code>boolean</code> | Whether exit transitions should be monitored. | <code>true</code> | 8.0.30 |
|
|
564
|
+
| **`payload`** | <code><a href="#record">Record</a><string, unknown></code> | Base JSON payload merged into every native transition POST and listener event. | | 8.0.30 |
|
|
565
|
+
| **`requestPermissions`** | <code>boolean</code> | Whether the plugin should request the native location permission needed for geofencing. iOS geofencing needs Always location authorization. Android geofencing requests foreground location by default. Android background location is only requested when `backgroundLocation` is enabled. | <code>true</code> | 8.0.30 |
|
|
566
|
+
| **`backgroundLocation`** | <code>boolean</code> | Whether Android geofencing should opt into background location permission. The plugin does not add `ACCESS_BACKGROUND_LOCATION` to your app manifest. Leave this disabled if your app does not have Google Play approval for Android background location. Enable it only after adding `ACCESS_BACKGROUND_LOCATION` to your app manifest and when you need Android geofence transitions while the app is in the background. This option only affects Android. Android versions below 10 do not request an extra background-location runtime permission, but the option still gates native Android background geofence delivery. | <code>false</code> | 8.0.34 |
|
|
560
567
|
|
|
561
568
|
|
|
562
569
|
#### AddGeofenceOptions
|
package/android/src/main/java/com/capgo/capacitor_background_geolocation/BackgroundGeolocation.java
CHANGED
|
@@ -228,25 +228,34 @@ public class BackgroundGeolocation extends Plugin {
|
|
|
228
228
|
}
|
|
229
229
|
|
|
230
230
|
JSObject payload = call.getObject("payload", new JSObject());
|
|
231
|
-
|
|
231
|
+
boolean backgroundLocation = call.getBoolean("backgroundLocation", false);
|
|
232
|
+
GeofenceStore.saveSetup(
|
|
233
|
+
getContext(),
|
|
234
|
+
url,
|
|
235
|
+
call.getBoolean("notifyOnEntry", true),
|
|
236
|
+
call.getBoolean("notifyOnExit", true),
|
|
237
|
+
payload,
|
|
238
|
+
backgroundLocation
|
|
239
|
+
);
|
|
232
240
|
|
|
233
241
|
if (!call.getBoolean("requestPermissions", true)) {
|
|
234
242
|
call.resolve();
|
|
235
243
|
return;
|
|
236
244
|
}
|
|
237
245
|
|
|
238
|
-
requestGeofencePermissions(call)
|
|
246
|
+
requestGeofencePermissions(call, backgroundLocation)
|
|
239
247
|
.thenRun(call::resolve)
|
|
240
248
|
.exceptionally((throwable) -> {
|
|
241
|
-
call.reject(
|
|
249
|
+
call.reject(geofencePermissionMessage(backgroundLocation), "NOT_AUTHORIZED");
|
|
242
250
|
return null;
|
|
243
251
|
});
|
|
244
252
|
}
|
|
245
253
|
|
|
246
254
|
@PluginMethod
|
|
247
255
|
public void addGeofence(PluginCall call) {
|
|
248
|
-
|
|
249
|
-
|
|
256
|
+
boolean backgroundLocation = GeofenceStore.getBackgroundLocation(getContext());
|
|
257
|
+
if (!hasGeofencePermissions(backgroundLocation)) {
|
|
258
|
+
call.reject(geofencePermissionMessage(backgroundLocation), "NOT_AUTHORIZED");
|
|
250
259
|
return;
|
|
251
260
|
}
|
|
252
261
|
if (!isLocationEnabled(getContext())) {
|
|
@@ -322,7 +331,7 @@ public class BackgroundGeolocation extends Plugin {
|
|
|
322
331
|
})
|
|
323
332
|
.addOnFailureListener((exception) -> call.reject("Could not start monitoring the geofence", exception));
|
|
324
333
|
} catch (SecurityException exception) {
|
|
325
|
-
call.reject(
|
|
334
|
+
call.reject(geofencePermissionMessage(backgroundLocation), "NOT_AUTHORIZED", exception);
|
|
326
335
|
}
|
|
327
336
|
}
|
|
328
337
|
|
|
@@ -365,8 +374,8 @@ public class BackgroundGeolocation extends Plugin {
|
|
|
365
374
|
call.resolve(result);
|
|
366
375
|
}
|
|
367
376
|
|
|
368
|
-
private CompletableFuture<Void> requestGeofencePermissions(PluginCall call) {
|
|
369
|
-
if (hasGeofencePermissions()) {
|
|
377
|
+
private CompletableFuture<Void> requestGeofencePermissions(PluginCall call, boolean backgroundLocation) {
|
|
378
|
+
if (hasGeofencePermissions(backgroundLocation)) {
|
|
370
379
|
return CompletableFuture.completedFuture(null);
|
|
371
380
|
}
|
|
372
381
|
if (geofencePermissionFuture != null) {
|
|
@@ -378,7 +387,7 @@ public class BackgroundGeolocation extends Plugin {
|
|
|
378
387
|
requestPermissionForAlias("location", call, "geofenceLocationPermissionsCallback");
|
|
379
388
|
return future;
|
|
380
389
|
}
|
|
381
|
-
requestBackgroundLocationPermissionIfNeeded(call);
|
|
390
|
+
requestBackgroundLocationPermissionIfNeeded(call, backgroundLocation);
|
|
382
391
|
return future;
|
|
383
392
|
}
|
|
384
393
|
|
|
@@ -392,7 +401,7 @@ public class BackgroundGeolocation extends Plugin {
|
|
|
392
401
|
geofencePermissionFuture = null;
|
|
393
402
|
return;
|
|
394
403
|
}
|
|
395
|
-
requestBackgroundLocationPermissionIfNeeded(call);
|
|
404
|
+
requestBackgroundLocationPermissionIfNeeded(call, GeofenceStore.getBackgroundLocation(getContext()));
|
|
396
405
|
}
|
|
397
406
|
|
|
398
407
|
@PermissionCallback
|
|
@@ -409,8 +418,8 @@ public class BackgroundGeolocation extends Plugin {
|
|
|
409
418
|
geofencePermissionFuture = null;
|
|
410
419
|
}
|
|
411
420
|
|
|
412
|
-
private void requestBackgroundLocationPermissionIfNeeded(PluginCall call) {
|
|
413
|
-
if (hasBackgroundLocationPermission()) {
|
|
421
|
+
private void requestBackgroundLocationPermissionIfNeeded(PluginCall call, boolean backgroundLocation) {
|
|
422
|
+
if (!backgroundLocation || hasBackgroundLocationPermission()) {
|
|
414
423
|
geofencePermissionFuture.complete(null);
|
|
415
424
|
geofencePermissionFuture = null;
|
|
416
425
|
return;
|
|
@@ -418,8 +427,8 @@ public class BackgroundGeolocation extends Plugin {
|
|
|
418
427
|
requestPermissionForAlias("backgroundLocation", call, "geofenceBackgroundPermissionsCallback");
|
|
419
428
|
}
|
|
420
429
|
|
|
421
|
-
private boolean hasGeofencePermissions() {
|
|
422
|
-
return getPermissionState("location") == PermissionState.GRANTED && hasBackgroundLocationPermission();
|
|
430
|
+
private boolean hasGeofencePermissions(boolean backgroundLocation) {
|
|
431
|
+
return getPermissionState("location") == PermissionState.GRANTED && (!backgroundLocation || hasBackgroundLocationPermission());
|
|
423
432
|
}
|
|
424
433
|
|
|
425
434
|
private boolean hasBackgroundLocationPermission() {
|
|
@@ -432,6 +441,13 @@ public class BackgroundGeolocation extends Plugin {
|
|
|
432
441
|
);
|
|
433
442
|
}
|
|
434
443
|
|
|
444
|
+
private String geofencePermissionMessage(boolean backgroundLocation) {
|
|
445
|
+
if (backgroundLocation) {
|
|
446
|
+
return "Background location permission is required for geofencing";
|
|
447
|
+
}
|
|
448
|
+
return "Location permission is required for geofencing";
|
|
449
|
+
}
|
|
450
|
+
|
|
435
451
|
private GeofencingClient getGeofencingClient() {
|
|
436
452
|
return LocationServices.getGeofencingClient(getContext());
|
|
437
453
|
}
|
package/android/src/main/java/com/capgo/capacitor_background_geolocation/GeofenceBootReceiver.java
CHANGED
|
@@ -34,6 +34,9 @@ public class GeofenceBootReceiver extends BroadcastReceiver {
|
|
|
34
34
|
|
|
35
35
|
private static List<Task<Void>> restorePersistedGeofences(Context context) {
|
|
36
36
|
List<Task<Void>> tasks = new ArrayList<>();
|
|
37
|
+
if (!GeofenceStore.getBackgroundLocation(context)) {
|
|
38
|
+
return tasks;
|
|
39
|
+
}
|
|
37
40
|
var client = LocationServices.getGeofencingClient(context);
|
|
38
41
|
for (String identifier : GeofenceStore.getRegionIds(context)) {
|
|
39
42
|
JSONObject region = GeofenceStore.getRegion(context, identifier);
|
|
@@ -33,13 +33,21 @@ final class GeofenceStore {
|
|
|
33
33
|
private static final String KEY_URL = "url";
|
|
34
34
|
private static final String KEY_NOTIFY_ON_ENTRY = "notifyOnEntry";
|
|
35
35
|
private static final String KEY_NOTIFY_ON_EXIT = "notifyOnExit";
|
|
36
|
+
private static final String KEY_BACKGROUND_LOCATION = "backgroundLocation";
|
|
36
37
|
private static final String KEY_PAYLOAD = "payload";
|
|
37
38
|
private static final String KEY_REGION_IDS = "regionIds";
|
|
38
39
|
private static final String KEY_REGION_PREFIX = "region.";
|
|
39
40
|
|
|
40
41
|
private GeofenceStore() {}
|
|
41
42
|
|
|
42
|
-
static void saveSetup(
|
|
43
|
+
static void saveSetup(
|
|
44
|
+
Context context,
|
|
45
|
+
String url,
|
|
46
|
+
boolean notifyOnEntry,
|
|
47
|
+
boolean notifyOnExit,
|
|
48
|
+
JSONObject payload,
|
|
49
|
+
boolean backgroundLocation
|
|
50
|
+
) {
|
|
43
51
|
SharedPreferences.Editor editor = prefs(context).edit();
|
|
44
52
|
if (url == null || url.isEmpty()) {
|
|
45
53
|
editor.remove(KEY_URL);
|
|
@@ -48,6 +56,7 @@ final class GeofenceStore {
|
|
|
48
56
|
}
|
|
49
57
|
editor.putBoolean(KEY_NOTIFY_ON_ENTRY, notifyOnEntry);
|
|
50
58
|
editor.putBoolean(KEY_NOTIFY_ON_EXIT, notifyOnExit);
|
|
59
|
+
editor.putBoolean(KEY_BACKGROUND_LOCATION, backgroundLocation);
|
|
51
60
|
editor.putString(KEY_PAYLOAD, payload == null ? new JSONObject().toString() : payload.toString());
|
|
52
61
|
editor.apply();
|
|
53
62
|
}
|
|
@@ -64,6 +73,10 @@ final class GeofenceStore {
|
|
|
64
73
|
return prefs(context).getBoolean(KEY_NOTIFY_ON_EXIT, true);
|
|
65
74
|
}
|
|
66
75
|
|
|
76
|
+
static boolean getBackgroundLocation(Context context) {
|
|
77
|
+
return prefs(context).getBoolean(KEY_BACKGROUND_LOCATION, false);
|
|
78
|
+
}
|
|
79
|
+
|
|
67
80
|
static void saveRegion(
|
|
68
81
|
Context context,
|
|
69
82
|
String identifier,
|
|
@@ -170,6 +183,9 @@ final class GeofenceStore {
|
|
|
170
183
|
}
|
|
171
184
|
|
|
172
185
|
static void enqueueTransition(Context context, JSONObject data) {
|
|
186
|
+
if (!getBackgroundLocation(context)) {
|
|
187
|
+
return;
|
|
188
|
+
}
|
|
173
189
|
if (getUrl(context) == null || getUrl(context).isEmpty()) {
|
|
174
190
|
return;
|
|
175
191
|
}
|
package/dist/docs.json
CHANGED
|
@@ -163,10 +163,10 @@
|
|
|
163
163
|
},
|
|
164
164
|
{
|
|
165
165
|
"name": "example",
|
|
166
|
-
"text": "await BackgroundGeolocation.setupGeofencing({\n
|
|
166
|
+
"text": "await BackgroundGeolocation.setupGeofencing({\n notifyOnEntry: true,\n notifyOnExit: true,\n payload: { userId: \"123\" }\n});"
|
|
167
167
|
}
|
|
168
168
|
],
|
|
169
|
-
"docs": "Configures native geofence transition handling.\n\nCall this before adding geofences when you need native background POSTs
|
|
169
|
+
"docs": "Configures native geofence transition handling.\n\nCall this before adding geofences when you need default entry/exit settings\nor native background POSTs. Android background POSTs require\n`backgroundLocation: true`.",
|
|
170
170
|
"complexTypes": [
|
|
171
171
|
"GeofenceSetupOptions"
|
|
172
172
|
],
|
|
@@ -741,7 +741,7 @@
|
|
|
741
741
|
{
|
|
742
742
|
"name": "GeofenceSetupOptions",
|
|
743
743
|
"slug": "geofencesetupoptions",
|
|
744
|
-
"docs": "Options for configuring native geofence transition handling.\n\nWhen `url` is provided, native
|
|
744
|
+
"docs": "Options for configuring native geofence transition handling.\n\nWhen `url` is provided, native code can send a JSON `POST` whenever a\nmonitored region is entered or exited. Android background POST delivery\nrequires `backgroundLocation: true`.",
|
|
745
745
|
"tags": [
|
|
746
746
|
{
|
|
747
747
|
"text": "8.0.30",
|
|
@@ -762,7 +762,7 @@
|
|
|
762
762
|
"name": "example"
|
|
763
763
|
}
|
|
764
764
|
],
|
|
765
|
-
"docs": "Endpoint that receives geofence transition payloads
|
|
765
|
+
"docs": "Endpoint that receives geofence transition payloads.\n\nOn Android, native background POST delivery requires `backgroundLocation: true`.",
|
|
766
766
|
"complexTypes": [],
|
|
767
767
|
"type": "string | undefined"
|
|
768
768
|
},
|
|
@@ -840,7 +840,27 @@
|
|
|
840
840
|
"name": "example"
|
|
841
841
|
}
|
|
842
842
|
],
|
|
843
|
-
"docs": "Whether the plugin should request the native location permission needed for geofencing.\n\niOS geofencing needs Always location authorization. Android
|
|
843
|
+
"docs": "Whether the plugin should request the native location permission needed for geofencing.\n\niOS geofencing needs Always location authorization. Android geofencing requests\nforeground location by default. Android background location is only requested when\n`backgroundLocation` is enabled.",
|
|
844
|
+
"complexTypes": [],
|
|
845
|
+
"type": "boolean | undefined"
|
|
846
|
+
},
|
|
847
|
+
{
|
|
848
|
+
"name": "backgroundLocation",
|
|
849
|
+
"tags": [
|
|
850
|
+
{
|
|
851
|
+
"text": "8.0.34",
|
|
852
|
+
"name": "since"
|
|
853
|
+
},
|
|
854
|
+
{
|
|
855
|
+
"text": "false",
|
|
856
|
+
"name": "default"
|
|
857
|
+
},
|
|
858
|
+
{
|
|
859
|
+
"text": "false",
|
|
860
|
+
"name": "example"
|
|
861
|
+
}
|
|
862
|
+
],
|
|
863
|
+
"docs": "Whether Android geofencing should opt into background location permission.\n\nThe plugin does not add `ACCESS_BACKGROUND_LOCATION` to your app manifest.\nLeave this disabled if your app does not have Google Play approval for Android\nbackground location. Enable it only after adding `ACCESS_BACKGROUND_LOCATION`\nto your app manifest and when you need Android geofence transitions while the\napp is in the background.\n\nThis option only affects Android. Android versions below 10 do not request\nan extra background-location runtime permission, but the option still gates\nnative Android background geofence delivery.",
|
|
844
864
|
"complexTypes": [],
|
|
845
865
|
"type": "boolean | undefined"
|
|
846
866
|
}
|
|
@@ -194,9 +194,9 @@ export interface SetPlannedRouteOptions {
|
|
|
194
194
|
/**
|
|
195
195
|
* Options for configuring native geofence transition handling.
|
|
196
196
|
*
|
|
197
|
-
* When `url` is provided, native
|
|
198
|
-
*
|
|
199
|
-
*
|
|
197
|
+
* When `url` is provided, native code can send a JSON `POST` whenever a
|
|
198
|
+
* monitored region is entered or exited. Android background POST delivery
|
|
199
|
+
* requires `backgroundLocation: true`.
|
|
200
200
|
*
|
|
201
201
|
* @since 8.0.30
|
|
202
202
|
*/
|
|
@@ -204,6 +204,8 @@ export interface GeofenceSetupOptions {
|
|
|
204
204
|
/**
|
|
205
205
|
* Endpoint that receives geofence transition payloads.
|
|
206
206
|
*
|
|
207
|
+
* On Android, native background POST delivery requires `backgroundLocation: true`.
|
|
208
|
+
*
|
|
207
209
|
* @since 8.0.30
|
|
208
210
|
* @example "https://api.example.com/geofences"
|
|
209
211
|
*/
|
|
@@ -234,14 +236,33 @@ export interface GeofenceSetupOptions {
|
|
|
234
236
|
/**
|
|
235
237
|
* Whether the plugin should request the native location permission needed for geofencing.
|
|
236
238
|
*
|
|
237
|
-
* iOS geofencing needs Always location authorization. Android
|
|
238
|
-
*
|
|
239
|
+
* iOS geofencing needs Always location authorization. Android geofencing requests
|
|
240
|
+
* foreground location by default. Android background location is only requested when
|
|
241
|
+
* `backgroundLocation` is enabled.
|
|
239
242
|
*
|
|
240
243
|
* @since 8.0.30
|
|
241
244
|
* @default true
|
|
242
245
|
* @example true
|
|
243
246
|
*/
|
|
244
247
|
requestPermissions?: boolean;
|
|
248
|
+
/**
|
|
249
|
+
* Whether Android geofencing should opt into background location permission.
|
|
250
|
+
*
|
|
251
|
+
* The plugin does not add `ACCESS_BACKGROUND_LOCATION` to your app manifest.
|
|
252
|
+
* Leave this disabled if your app does not have Google Play approval for Android
|
|
253
|
+
* background location. Enable it only after adding `ACCESS_BACKGROUND_LOCATION`
|
|
254
|
+
* to your app manifest and when you need Android geofence transitions while the
|
|
255
|
+
* app is in the background.
|
|
256
|
+
*
|
|
257
|
+
* This option only affects Android. Android versions below 10 do not request
|
|
258
|
+
* an extra background-location runtime permission, but the option still gates
|
|
259
|
+
* native Android background geofence delivery.
|
|
260
|
+
*
|
|
261
|
+
* @since 8.0.34
|
|
262
|
+
* @default false
|
|
263
|
+
* @example false
|
|
264
|
+
*/
|
|
265
|
+
backgroundLocation?: boolean;
|
|
245
266
|
}
|
|
246
267
|
/**
|
|
247
268
|
* A circular geofence region.
|
|
@@ -494,8 +515,9 @@ export interface BackgroundGeolocationPlugin {
|
|
|
494
515
|
/**
|
|
495
516
|
* Configures native geofence transition handling.
|
|
496
517
|
*
|
|
497
|
-
* Call this before adding geofences when you need
|
|
498
|
-
* or
|
|
518
|
+
* Call this before adding geofences when you need default entry/exit settings
|
|
519
|
+
* or native background POSTs. Android background POSTs require
|
|
520
|
+
* `backgroundLocation: true`.
|
|
499
521
|
*
|
|
500
522
|
* @param options The geofence configuration options
|
|
501
523
|
* @returns A promise that resolves once geofencing is configured
|
|
@@ -503,7 +525,6 @@ export interface BackgroundGeolocationPlugin {
|
|
|
503
525
|
* @since 8.0.30
|
|
504
526
|
* @example
|
|
505
527
|
* await BackgroundGeolocation.setupGeofencing({
|
|
506
|
-
* url: "https://api.example.com/geofences",
|
|
507
528
|
* notifyOnEntry: true,
|
|
508
529
|
* notifyOnExit: true,
|
|
509
530
|
* payload: { userId: "123" }
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"definitions.js","sourceRoot":"","sources":["../../src/definitions.ts"],"names":[],"mappings":"","sourcesContent":["import type { PluginListenerHandle } from '@capacitor/core';\n\n/**\n * The options for configuring for location updates.\n *\n * @since 7.0.9\n */\nexport interface StartOptions {\n /**\n * If the \"backgroundMessage\" option is defined, the plugin will\n * provide location updates whether the app is in the background or the\n * foreground. If it is not defined, location updates are only\n * guaranteed in the foreground. This is true on both platforms.\n *\n * On Android, a notification must be shown to continue receiving\n * location updates in the background. This option specifies the text of\n * that notification.\n *\n * @since 7.0.9\n * @example \"Getting your location to provide better service\"\n */\n backgroundMessage?: string;\n /**\n * The title of the notification mentioned above.\n *\n * @since 7.0.9\n * @default \"Using your location\"\n * @example \"Location Service\"\n */\n backgroundTitle?: string;\n /**\n * Whether permissions should be requested from the user automatically,\n * if they are not already granted.\n *\n * @since 7.0.9\n * @default true\n * @example\n * // Auto-request permissions\n * requestPermissions: true\n *\n * // Don't auto-request, handle manually\n * requestPermissions: false\n */\n requestPermissions?: boolean;\n /**\n * If \"true\", stale locations may be delivered while the device\n * obtains a GPS fix. You are responsible for checking the \"time\"\n * property. If \"false\", locations are guaranteed to be up to date.\n *\n * @since 7.0.9\n * @default false\n * @example\n * // Allow stale locations for faster initial response\n * stale: true\n *\n * // Only fresh locations\n * stale: false\n */\n stale?: boolean;\n /**\n * The distance in meters that the device must move before a new location update is triggered.\n * This is used to filter out small movements and reduce the number of updates.\n *\n * @since 7.0.9\n * @default 0\n * @example\n * // Update every 10 meters\n * distanceFilter: 10\n *\n * // Update on any movement\n * distanceFilter: 0\n */\n distanceFilter?: number;\n}\n\n/**\n * Represents a geographical location with various attributes.\n * Contains all the standard location properties returned by GPS/network providers.\n *\n * @since 7.0.0\n */\nexport interface Location {\n /**\n * Latitude in degrees.\n * Range: -90.0 to +90.0\n *\n * @since 7.0.0\n * @example 40.7128\n */\n latitude: number;\n /**\n * Longitude in degrees.\n * Range: -180.0 to +180.0\n *\n * @since 7.0.0\n * @example -74.0060\n */\n longitude: number;\n /**\n * Radius of horizontal uncertainty in metres, with 68% confidence.\n * Lower values indicate more accurate location.\n *\n * @since 7.0.0\n * @example 5.0\n */\n accuracy: number;\n /**\n * Metres above sea level (or null if not available).\n *\n * @since 7.0.0\n * @example 10.5\n */\n altitude: number | null;\n /**\n * Vertical uncertainty in metres, with 68% confidence (or null if not available).\n *\n * @since 7.0.0\n * @example 3.0\n */\n altitudeAccuracy: number | null;\n /**\n * `true` if the location was simulated by software, rather than GPS.\n * Useful for detecting mock locations in development or testing.\n *\n * @since 7.0.0\n * @example false\n */\n simulated: boolean;\n /**\n * Deviation from true north in degrees (or null if not available).\n * Range: 0.0 to 360.0\n *\n * @since 7.0.0\n * @example 45.5\n */\n bearing: number | null;\n /**\n * Speed in metres per second (or null if not available).\n *\n * @since 7.0.0\n * @example 2.5\n */\n speed: number | null;\n /**\n * Time the location was produced, in milliseconds since the unix epoch.\n * Use this to check if a location is stale when using stale: true.\n *\n * @since 7.0.0\n * @example 1640995200000\n */\n time: number | null;\n}\n\n/**\n * Error object that may be passed to the location start callback.\n * Extends the standard Error with optional error codes.\n *\n * @since 7.0.0\n */\nexport interface CallbackError extends Error {\n /**\n * Optional error code for more specific error handling.\n *\n * @since 7.0.0\n * @example \"PERMISSION_DENIED\"\n */\n code?: string;\n}\n\nexport interface SetPlannedRouteOptions {\n /**\n * The name of the sound file to play.\n * Must be a valid sound relative path in the app's public folder to work for both web and native platforms.\n * There's no need to include the public folder in the path.\n * @since 7.0.10\n * @example \"notification.mp3\"\n * */\n soundFile: string;\n /**\n * The planned route as an array of longitude and latitude pairs.\n * Each pair represents a point on the route.\n * This is used to define a route that the user can follow.\n * The route is used to play a sound when the user deviates from it.\n * @since 7.0.11\n * @example [[-74.0060, 40.7128], [-118.2437, 34.0522]]\n */\n route: [number, number][];\n\n /**\n * The distance in meters that the user must deviate from the planned route to trigger the sound.\n * This is used to determine how far off the route the user can be before the sound is played.\n * If not specified, a default value of 50 meters is used.\n * @since 7.0.11\n * @default 50\n * @example 50\n */\n distance: number;\n}\n\n/**\n * Options for configuring native geofence transition handling.\n *\n * When `url` is provided, native iOS and Android code sends a JSON `POST`\n * whenever a monitored region is entered or exited. This keeps geofence\n * handling useful when the WebView is suspended.\n *\n * @since 8.0.30\n */\nexport interface GeofenceSetupOptions {\n /**\n * Endpoint that receives geofence transition payloads.\n *\n * @since 8.0.30\n * @example \"https://api.example.com/geofences\"\n */\n url?: string;\n\n /**\n * Whether entry transitions should be monitored.\n *\n * @since 8.0.30\n * @default true\n * @example true\n */\n notifyOnEntry?: boolean;\n\n /**\n * Whether exit transitions should be monitored.\n *\n * @since 8.0.30\n * @default true\n * @example true\n */\n notifyOnExit?: boolean;\n\n /**\n * Base JSON payload merged into every native transition POST and listener event.\n *\n * @since 8.0.30\n * @example { \"userId\": \"123\" }\n */\n payload?: Record<string, unknown>;\n\n /**\n * Whether the plugin should request the native location permission needed for geofencing.\n *\n * iOS geofencing needs Always location authorization. Android background geofencing\n * needs foreground location and, on Android 10+, background location permission.\n *\n * @since 8.0.30\n * @default true\n * @example true\n */\n requestPermissions?: boolean;\n}\n\n/**\n * A circular geofence region.\n *\n * @since 8.0.30\n */\nexport interface AddGeofenceOptions {\n /**\n * Latitude in degrees for the region center.\n *\n * @since 8.0.30\n * @example 40.7128\n */\n latitude: number;\n\n /**\n * Longitude in degrees for the region center.\n *\n * @since 8.0.30\n * @example -74.006\n */\n longitude: number;\n\n /**\n * Region radius in meters.\n *\n * @since 8.0.30\n * @default 50\n * @example 150\n */\n radius?: number;\n\n /**\n * Stable identifier for the geofence.\n *\n * @since 8.0.30\n * @example \"office\"\n */\n identifier: string;\n\n /**\n * Overrides the setup-level entry setting for this region.\n *\n * @since 8.0.30\n */\n notifyOnEntry?: boolean;\n\n /**\n * Overrides the setup-level exit setting for this region.\n *\n * @since 8.0.30\n */\n notifyOnExit?: boolean;\n\n /**\n * Region-specific payload merged over the setup payload.\n *\n * @since 8.0.30\n * @example { \"storeId\": \"nyc-1\" }\n */\n payload?: Record<string, unknown>;\n}\n\n/**\n * Options for removing a monitored geofence.\n *\n * @since 8.0.30\n */\nexport interface RemoveGeofenceOptions {\n /**\n * Identifier passed to `addGeofence`.\n *\n * @since 8.0.30\n * @example \"office\"\n */\n identifier: string;\n}\n\n/**\n * Result returned when listing monitored geofences.\n *\n * @since 8.0.30\n */\nexport interface MonitoredGeofencesResult {\n /**\n * Identifiers for all geofences currently monitored by this plugin.\n *\n * @since 8.0.30\n * @example [\"office\", \"warehouse\"]\n */\n regions: string[];\n}\n\n/**\n * Event emitted when a monitored geofence is entered or exited.\n *\n * The same data is also sent to the configured `url`, when one is set.\n *\n * @since 8.0.30\n */\nexport interface GeofenceTransitionEvent {\n /**\n * Identifier of the geofence that changed state.\n *\n * @since 8.0.30\n * @example \"office\"\n */\n identifier: string;\n\n /**\n * Transition name.\n *\n * @since 8.0.30\n * @example \"enter\"\n */\n transition: 'enter' | 'exit';\n\n /**\n * `true` for entry transitions, `false` for exit transitions.\n *\n * @since 8.0.30\n * @example true\n */\n enter: boolean;\n\n /**\n * Latitude in degrees for the monitored region center, when available.\n *\n * @since 8.0.30\n * @example 40.7128\n */\n latitude?: number;\n\n /**\n * Longitude in degrees for the monitored region center, when available.\n *\n * @since 8.0.30\n * @example -74.006\n */\n longitude?: number;\n\n /**\n * Region radius in meters, when available.\n *\n * @since 8.0.30\n * @example 150\n */\n radius?: number;\n\n /**\n * Merged setup and region payload.\n *\n * @since 8.0.30\n */\n payload?: Record<string, unknown>;\n}\n\n/**\n * Event emitted when native geofence monitoring fails.\n *\n * @since 8.0.30\n */\nexport interface GeofenceErrorEvent {\n /**\n * Identifier of the geofence that failed, when native APIs provide it.\n *\n * @since 8.0.30\n * @example \"office\"\n */\n identifier?: string;\n\n /**\n * Native platform error code.\n *\n * @since 8.0.30\n * @example 5\n */\n code?: number;\n\n /**\n * Native platform error message.\n *\n * @since 8.0.30\n */\n message: string;\n\n /**\n * Native error domain, when available.\n *\n * @since 8.0.30\n */\n domain?: string;\n}\n\n/**\n * Main plugin interface for background geolocation functionality.\n * Provides methods to manage location updates and access device settings.\n *\n * @since 7.0.0\n */\nexport interface BackgroundGeolocationPlugin {\n /**\n * To start listening for changes in the device's location, call this method.\n * A Promise is returned to indicate that it finished the call. The callback will be called every time a new location\n * is available, or if there was an error when calling this method. Don't rely on promise rejection for this.\n *\n * @param options The configuration options\n * @param callback The callback function invoked when a new location is available or an error occurs\n * @returns A promise that resolves when the method is successfully called\n *\n * @since 7.0.9\n * @example\n * await BackgroundGeolocation.start(\n * {\n * backgroundMessage: \"App is using your location in the background\",\n * backgroundTitle: \"Location Service\",\n * requestPermissions: true,\n * stale: false,\n * distanceFilter: 10\n * },\n * (location, error) => {\n * if (error) {\n * console.error('Location error:', error);\n * return;\n * }\n * if (location) {\n * console.log('New location:', location.latitude, location.longitude);\n * }\n * }\n * );\n */\n start(options: StartOptions, callback: (position?: Location, error?: CallbackError) => void): Promise<void>;\n\n /**\n * Stops location updates.\n *\n * @returns A promise that resolves when the plugin stops successfully removed\n *\n * @since 7.0.9\n * @example\n * await BackgroundGeolocation.stop();\n */\n stop(): Promise<void>;\n\n /**\n * Opens the device's location settings page.\n * Useful for directing users to enable location services or adjust permissions.\n *\n * @returns A promise that resolves when the settings page is opened\n *\n * @since 7.0.0\n * @example\n * // Direct user to location settings\n * await BackgroundGeolocation.openSettings();\n */\n openSettings(): Promise<void>;\n\n /**\n * Plays a sound file when the user deviates from the planned route.\n * This should be used to play a sound (in the background too, only for native).\n *\n * @param options The options for setting the planned route and sound file\n * @returns A promise that resolves when the route is set successfully\n *\n * @since 7.0.11\n * @example\n * await BackgroundGeolocation.setPlannedRoute({\n * soundFile: \"notification.mp3\",\n * route: [[-74.0060, 40.7128], [-118.2437, 34.0522]]\n * });\n */\n setPlannedRoute(options: SetPlannedRouteOptions): Promise<void>;\n\n /**\n * Configures native geofence transition handling.\n *\n * Call this before adding geofences when you need native background POSTs\n * or default entry/exit settings.\n *\n * @param options The geofence configuration options\n * @returns A promise that resolves once geofencing is configured\n *\n * @since 8.0.30\n * @example\n * await BackgroundGeolocation.setupGeofencing({\n * url: \"https://api.example.com/geofences\",\n * notifyOnEntry: true,\n * notifyOnExit: true,\n * payload: { userId: \"123\" }\n * });\n */\n setupGeofencing(options: GeofenceSetupOptions): Promise<void>;\n\n /**\n * Starts monitoring a circular native geofence.\n *\n * @param options The geofence region options\n * @returns A promise that resolves when native monitoring starts\n *\n * @since 8.0.30\n * @example\n * await BackgroundGeolocation.addGeofence({\n * identifier: \"office\",\n * latitude: 40.7128,\n * longitude: -74.006,\n * radius: 150\n * });\n */\n addGeofence(options: AddGeofenceOptions): Promise<void>;\n\n /**\n * Stops monitoring one geofence.\n *\n * @param options The geofence identifier\n * @returns A promise that resolves when native monitoring stops\n *\n * @since 8.0.30\n * @example\n * await BackgroundGeolocation.removeGeofence({ identifier: \"office\" });\n */\n removeGeofence(options: RemoveGeofenceOptions): Promise<void>;\n\n /**\n * Stops monitoring every geofence registered by this plugin.\n *\n * @returns A promise that resolves when all native geofences are removed\n *\n * @since 8.0.30\n * @example\n * await BackgroundGeolocation.removeAllGeofences();\n */\n removeAllGeofences(): Promise<void>;\n\n /**\n * Lists the geofence identifiers currently monitored by this plugin.\n *\n * @returns A promise with monitored geofence identifiers\n *\n * @since 8.0.30\n * @example\n * const { regions } = await BackgroundGeolocation.getMonitoredGeofences();\n */\n getMonitoredGeofences(): Promise<MonitoredGeofencesResult>;\n\n /**\n * Listens for geofence enter/exit transitions while the WebView is alive.\n *\n * Native `url` delivery configured through `setupGeofencing` is used for\n * background-safe delivery.\n *\n * @since 8.0.30\n * @example\n * const handle = await BackgroundGeolocation.addListener(\n * \"geofenceTransition\",\n * (event) => console.log(event.identifier, event.transition)\n * );\n */\n addListener(\n eventName: 'geofenceTransition',\n listenerFunc: (event: GeofenceTransitionEvent) => void,\n ): Promise<PluginListenerHandle>;\n\n /**\n * Listens for native geofence monitoring errors while the WebView is alive.\n *\n * @since 8.0.30\n * @example\n * const handle = await BackgroundGeolocation.addListener(\n * \"geofenceError\",\n * (event) => console.error(event.identifier, event.message)\n * );\n */\n addListener(\n eventName: 'geofenceError',\n listenerFunc: (event: GeofenceErrorEvent) => void,\n ): Promise<PluginListenerHandle>;\n\n /**\n * Get the native Capacitor plugin version\n *\n * @returns {Promise<{ id: string }>} an Promise with version for this device\n * @throws An error if the something went wrong\n */\n getPluginVersion(): Promise<{ version: string }>;\n}\n"]}
|
|
1
|
+
{"version":3,"file":"definitions.js","sourceRoot":"","sources":["../../src/definitions.ts"],"names":[],"mappings":"","sourcesContent":["import type { PluginListenerHandle } from '@capacitor/core';\n\n/**\n * The options for configuring for location updates.\n *\n * @since 7.0.9\n */\nexport interface StartOptions {\n /**\n * If the \"backgroundMessage\" option is defined, the plugin will\n * provide location updates whether the app is in the background or the\n * foreground. If it is not defined, location updates are only\n * guaranteed in the foreground. This is true on both platforms.\n *\n * On Android, a notification must be shown to continue receiving\n * location updates in the background. This option specifies the text of\n * that notification.\n *\n * @since 7.0.9\n * @example \"Getting your location to provide better service\"\n */\n backgroundMessage?: string;\n /**\n * The title of the notification mentioned above.\n *\n * @since 7.0.9\n * @default \"Using your location\"\n * @example \"Location Service\"\n */\n backgroundTitle?: string;\n /**\n * Whether permissions should be requested from the user automatically,\n * if they are not already granted.\n *\n * @since 7.0.9\n * @default true\n * @example\n * // Auto-request permissions\n * requestPermissions: true\n *\n * // Don't auto-request, handle manually\n * requestPermissions: false\n */\n requestPermissions?: boolean;\n /**\n * If \"true\", stale locations may be delivered while the device\n * obtains a GPS fix. You are responsible for checking the \"time\"\n * property. If \"false\", locations are guaranteed to be up to date.\n *\n * @since 7.0.9\n * @default false\n * @example\n * // Allow stale locations for faster initial response\n * stale: true\n *\n * // Only fresh locations\n * stale: false\n */\n stale?: boolean;\n /**\n * The distance in meters that the device must move before a new location update is triggered.\n * This is used to filter out small movements and reduce the number of updates.\n *\n * @since 7.0.9\n * @default 0\n * @example\n * // Update every 10 meters\n * distanceFilter: 10\n *\n * // Update on any movement\n * distanceFilter: 0\n */\n distanceFilter?: number;\n}\n\n/**\n * Represents a geographical location with various attributes.\n * Contains all the standard location properties returned by GPS/network providers.\n *\n * @since 7.0.0\n */\nexport interface Location {\n /**\n * Latitude in degrees.\n * Range: -90.0 to +90.0\n *\n * @since 7.0.0\n * @example 40.7128\n */\n latitude: number;\n /**\n * Longitude in degrees.\n * Range: -180.0 to +180.0\n *\n * @since 7.0.0\n * @example -74.0060\n */\n longitude: number;\n /**\n * Radius of horizontal uncertainty in metres, with 68% confidence.\n * Lower values indicate more accurate location.\n *\n * @since 7.0.0\n * @example 5.0\n */\n accuracy: number;\n /**\n * Metres above sea level (or null if not available).\n *\n * @since 7.0.0\n * @example 10.5\n */\n altitude: number | null;\n /**\n * Vertical uncertainty in metres, with 68% confidence (or null if not available).\n *\n * @since 7.0.0\n * @example 3.0\n */\n altitudeAccuracy: number | null;\n /**\n * `true` if the location was simulated by software, rather than GPS.\n * Useful for detecting mock locations in development or testing.\n *\n * @since 7.0.0\n * @example false\n */\n simulated: boolean;\n /**\n * Deviation from true north in degrees (or null if not available).\n * Range: 0.0 to 360.0\n *\n * @since 7.0.0\n * @example 45.5\n */\n bearing: number | null;\n /**\n * Speed in metres per second (or null if not available).\n *\n * @since 7.0.0\n * @example 2.5\n */\n speed: number | null;\n /**\n * Time the location was produced, in milliseconds since the unix epoch.\n * Use this to check if a location is stale when using stale: true.\n *\n * @since 7.0.0\n * @example 1640995200000\n */\n time: number | null;\n}\n\n/**\n * Error object that may be passed to the location start callback.\n * Extends the standard Error with optional error codes.\n *\n * @since 7.0.0\n */\nexport interface CallbackError extends Error {\n /**\n * Optional error code for more specific error handling.\n *\n * @since 7.0.0\n * @example \"PERMISSION_DENIED\"\n */\n code?: string;\n}\n\nexport interface SetPlannedRouteOptions {\n /**\n * The name of the sound file to play.\n * Must be a valid sound relative path in the app's public folder to work for both web and native platforms.\n * There's no need to include the public folder in the path.\n * @since 7.0.10\n * @example \"notification.mp3\"\n * */\n soundFile: string;\n /**\n * The planned route as an array of longitude and latitude pairs.\n * Each pair represents a point on the route.\n * This is used to define a route that the user can follow.\n * The route is used to play a sound when the user deviates from it.\n * @since 7.0.11\n * @example [[-74.0060, 40.7128], [-118.2437, 34.0522]]\n */\n route: [number, number][];\n\n /**\n * The distance in meters that the user must deviate from the planned route to trigger the sound.\n * This is used to determine how far off the route the user can be before the sound is played.\n * If not specified, a default value of 50 meters is used.\n * @since 7.0.11\n * @default 50\n * @example 50\n */\n distance: number;\n}\n\n/**\n * Options for configuring native geofence transition handling.\n *\n * When `url` is provided, native code can send a JSON `POST` whenever a\n * monitored region is entered or exited. Android background POST delivery\n * requires `backgroundLocation: true`.\n *\n * @since 8.0.30\n */\nexport interface GeofenceSetupOptions {\n /**\n * Endpoint that receives geofence transition payloads.\n *\n * On Android, native background POST delivery requires `backgroundLocation: true`.\n *\n * @since 8.0.30\n * @example \"https://api.example.com/geofences\"\n */\n url?: string;\n\n /**\n * Whether entry transitions should be monitored.\n *\n * @since 8.0.30\n * @default true\n * @example true\n */\n notifyOnEntry?: boolean;\n\n /**\n * Whether exit transitions should be monitored.\n *\n * @since 8.0.30\n * @default true\n * @example true\n */\n notifyOnExit?: boolean;\n\n /**\n * Base JSON payload merged into every native transition POST and listener event.\n *\n * @since 8.0.30\n * @example { \"userId\": \"123\" }\n */\n payload?: Record<string, unknown>;\n\n /**\n * Whether the plugin should request the native location permission needed for geofencing.\n *\n * iOS geofencing needs Always location authorization. Android geofencing requests\n * foreground location by default. Android background location is only requested when\n * `backgroundLocation` is enabled.\n *\n * @since 8.0.30\n * @default true\n * @example true\n */\n requestPermissions?: boolean;\n\n /**\n * Whether Android geofencing should opt into background location permission.\n *\n * The plugin does not add `ACCESS_BACKGROUND_LOCATION` to your app manifest.\n * Leave this disabled if your app does not have Google Play approval for Android\n * background location. Enable it only after adding `ACCESS_BACKGROUND_LOCATION`\n * to your app manifest and when you need Android geofence transitions while the\n * app is in the background.\n *\n * This option only affects Android. Android versions below 10 do not request\n * an extra background-location runtime permission, but the option still gates\n * native Android background geofence delivery.\n *\n * @since 8.0.34\n * @default false\n * @example false\n */\n backgroundLocation?: boolean;\n}\n\n/**\n * A circular geofence region.\n *\n * @since 8.0.30\n */\nexport interface AddGeofenceOptions {\n /**\n * Latitude in degrees for the region center.\n *\n * @since 8.0.30\n * @example 40.7128\n */\n latitude: number;\n\n /**\n * Longitude in degrees for the region center.\n *\n * @since 8.0.30\n * @example -74.006\n */\n longitude: number;\n\n /**\n * Region radius in meters.\n *\n * @since 8.0.30\n * @default 50\n * @example 150\n */\n radius?: number;\n\n /**\n * Stable identifier for the geofence.\n *\n * @since 8.0.30\n * @example \"office\"\n */\n identifier: string;\n\n /**\n * Overrides the setup-level entry setting for this region.\n *\n * @since 8.0.30\n */\n notifyOnEntry?: boolean;\n\n /**\n * Overrides the setup-level exit setting for this region.\n *\n * @since 8.0.30\n */\n notifyOnExit?: boolean;\n\n /**\n * Region-specific payload merged over the setup payload.\n *\n * @since 8.0.30\n * @example { \"storeId\": \"nyc-1\" }\n */\n payload?: Record<string, unknown>;\n}\n\n/**\n * Options for removing a monitored geofence.\n *\n * @since 8.0.30\n */\nexport interface RemoveGeofenceOptions {\n /**\n * Identifier passed to `addGeofence`.\n *\n * @since 8.0.30\n * @example \"office\"\n */\n identifier: string;\n}\n\n/**\n * Result returned when listing monitored geofences.\n *\n * @since 8.0.30\n */\nexport interface MonitoredGeofencesResult {\n /**\n * Identifiers for all geofences currently monitored by this plugin.\n *\n * @since 8.0.30\n * @example [\"office\", \"warehouse\"]\n */\n regions: string[];\n}\n\n/**\n * Event emitted when a monitored geofence is entered or exited.\n *\n * The same data is also sent to the configured `url`, when one is set.\n *\n * @since 8.0.30\n */\nexport interface GeofenceTransitionEvent {\n /**\n * Identifier of the geofence that changed state.\n *\n * @since 8.0.30\n * @example \"office\"\n */\n identifier: string;\n\n /**\n * Transition name.\n *\n * @since 8.0.30\n * @example \"enter\"\n */\n transition: 'enter' | 'exit';\n\n /**\n * `true` for entry transitions, `false` for exit transitions.\n *\n * @since 8.0.30\n * @example true\n */\n enter: boolean;\n\n /**\n * Latitude in degrees for the monitored region center, when available.\n *\n * @since 8.0.30\n * @example 40.7128\n */\n latitude?: number;\n\n /**\n * Longitude in degrees for the monitored region center, when available.\n *\n * @since 8.0.30\n * @example -74.006\n */\n longitude?: number;\n\n /**\n * Region radius in meters, when available.\n *\n * @since 8.0.30\n * @example 150\n */\n radius?: number;\n\n /**\n * Merged setup and region payload.\n *\n * @since 8.0.30\n */\n payload?: Record<string, unknown>;\n}\n\n/**\n * Event emitted when native geofence monitoring fails.\n *\n * @since 8.0.30\n */\nexport interface GeofenceErrorEvent {\n /**\n * Identifier of the geofence that failed, when native APIs provide it.\n *\n * @since 8.0.30\n * @example \"office\"\n */\n identifier?: string;\n\n /**\n * Native platform error code.\n *\n * @since 8.0.30\n * @example 5\n */\n code?: number;\n\n /**\n * Native platform error message.\n *\n * @since 8.0.30\n */\n message: string;\n\n /**\n * Native error domain, when available.\n *\n * @since 8.0.30\n */\n domain?: string;\n}\n\n/**\n * Main plugin interface for background geolocation functionality.\n * Provides methods to manage location updates and access device settings.\n *\n * @since 7.0.0\n */\nexport interface BackgroundGeolocationPlugin {\n /**\n * To start listening for changes in the device's location, call this method.\n * A Promise is returned to indicate that it finished the call. The callback will be called every time a new location\n * is available, or if there was an error when calling this method. Don't rely on promise rejection for this.\n *\n * @param options The configuration options\n * @param callback The callback function invoked when a new location is available or an error occurs\n * @returns A promise that resolves when the method is successfully called\n *\n * @since 7.0.9\n * @example\n * await BackgroundGeolocation.start(\n * {\n * backgroundMessage: \"App is using your location in the background\",\n * backgroundTitle: \"Location Service\",\n * requestPermissions: true,\n * stale: false,\n * distanceFilter: 10\n * },\n * (location, error) => {\n * if (error) {\n * console.error('Location error:', error);\n * return;\n * }\n * if (location) {\n * console.log('New location:', location.latitude, location.longitude);\n * }\n * }\n * );\n */\n start(options: StartOptions, callback: (position?: Location, error?: CallbackError) => void): Promise<void>;\n\n /**\n * Stops location updates.\n *\n * @returns A promise that resolves when the plugin stops successfully removed\n *\n * @since 7.0.9\n * @example\n * await BackgroundGeolocation.stop();\n */\n stop(): Promise<void>;\n\n /**\n * Opens the device's location settings page.\n * Useful for directing users to enable location services or adjust permissions.\n *\n * @returns A promise that resolves when the settings page is opened\n *\n * @since 7.0.0\n * @example\n * // Direct user to location settings\n * await BackgroundGeolocation.openSettings();\n */\n openSettings(): Promise<void>;\n\n /**\n * Plays a sound file when the user deviates from the planned route.\n * This should be used to play a sound (in the background too, only for native).\n *\n * @param options The options for setting the planned route and sound file\n * @returns A promise that resolves when the route is set successfully\n *\n * @since 7.0.11\n * @example\n * await BackgroundGeolocation.setPlannedRoute({\n * soundFile: \"notification.mp3\",\n * route: [[-74.0060, 40.7128], [-118.2437, 34.0522]]\n * });\n */\n setPlannedRoute(options: SetPlannedRouteOptions): Promise<void>;\n\n /**\n * Configures native geofence transition handling.\n *\n * Call this before adding geofences when you need default entry/exit settings\n * or native background POSTs. Android background POSTs require\n * `backgroundLocation: true`.\n *\n * @param options The geofence configuration options\n * @returns A promise that resolves once geofencing is configured\n *\n * @since 8.0.30\n * @example\n * await BackgroundGeolocation.setupGeofencing({\n * notifyOnEntry: true,\n * notifyOnExit: true,\n * payload: { userId: \"123\" }\n * });\n */\n setupGeofencing(options: GeofenceSetupOptions): Promise<void>;\n\n /**\n * Starts monitoring a circular native geofence.\n *\n * @param options The geofence region options\n * @returns A promise that resolves when native monitoring starts\n *\n * @since 8.0.30\n * @example\n * await BackgroundGeolocation.addGeofence({\n * identifier: \"office\",\n * latitude: 40.7128,\n * longitude: -74.006,\n * radius: 150\n * });\n */\n addGeofence(options: AddGeofenceOptions): Promise<void>;\n\n /**\n * Stops monitoring one geofence.\n *\n * @param options The geofence identifier\n * @returns A promise that resolves when native monitoring stops\n *\n * @since 8.0.30\n * @example\n * await BackgroundGeolocation.removeGeofence({ identifier: \"office\" });\n */\n removeGeofence(options: RemoveGeofenceOptions): Promise<void>;\n\n /**\n * Stops monitoring every geofence registered by this plugin.\n *\n * @returns A promise that resolves when all native geofences are removed\n *\n * @since 8.0.30\n * @example\n * await BackgroundGeolocation.removeAllGeofences();\n */\n removeAllGeofences(): Promise<void>;\n\n /**\n * Lists the geofence identifiers currently monitored by this plugin.\n *\n * @returns A promise with monitored geofence identifiers\n *\n * @since 8.0.30\n * @example\n * const { regions } = await BackgroundGeolocation.getMonitoredGeofences();\n */\n getMonitoredGeofences(): Promise<MonitoredGeofencesResult>;\n\n /**\n * Listens for geofence enter/exit transitions while the WebView is alive.\n *\n * Native `url` delivery configured through `setupGeofencing` is used for\n * background-safe delivery.\n *\n * @since 8.0.30\n * @example\n * const handle = await BackgroundGeolocation.addListener(\n * \"geofenceTransition\",\n * (event) => console.log(event.identifier, event.transition)\n * );\n */\n addListener(\n eventName: 'geofenceTransition',\n listenerFunc: (event: GeofenceTransitionEvent) => void,\n ): Promise<PluginListenerHandle>;\n\n /**\n * Listens for native geofence monitoring errors while the WebView is alive.\n *\n * @since 8.0.30\n * @example\n * const handle = await BackgroundGeolocation.addListener(\n * \"geofenceError\",\n * (event) => console.error(event.identifier, event.message)\n * );\n */\n addListener(\n eventName: 'geofenceError',\n listenerFunc: (event: GeofenceErrorEvent) => void,\n ): Promise<PluginListenerHandle>;\n\n /**\n * Get the native Capacitor plugin version\n *\n * @returns {Promise<{ id: string }>} an Promise with version for this device\n * @throws An error if the something went wrong\n */\n getPluginVersion(): Promise<{ version: string }>;\n}\n"]}
|
package/ios/Sources/CapgoBackgroundGeolocationPlugin/CapgoCapacitorBackgroundGeolocationPlugin.swift
CHANGED
|
@@ -38,7 +38,7 @@ func formatLocation(_ location: CLLocation) -> PluginCallResultData {
|
|
|
38
38
|
@objc(BackgroundGeolocation)
|
|
39
39
|
// swiftlint:disable:next type_body_length
|
|
40
40
|
public class BackgroundGeolocation: CAPPlugin, CLLocationManagerDelegate, CAPBridgedPlugin {
|
|
41
|
-
private let pluginVersion: String = "8.0.
|
|
41
|
+
private let pluginVersion: String = "8.0.35"
|
|
42
42
|
public let identifier = "BackgroundGeolocationPlugin"
|
|
43
43
|
public let jsName = "BackgroundGeolocation"
|
|
44
44
|
public let pluginMethods: [CAPPluginMethod] = [
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@capgo/background-geolocation",
|
|
3
|
-
"version": "8.0.
|
|
3
|
+
"version": "8.0.35",
|
|
4
4
|
"description": "Accurate background geolocation and native geofencing for Capacitor apps on iOS and Android.",
|
|
5
5
|
"main": "dist/plugin.cjs.js",
|
|
6
6
|
"module": "dist/esm/index.js",
|