react-native-bg-geolocation 0.2.0
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/BgGeolocation.podspec +39 -0
- package/LICENSE +20 -0
- package/README.md +366 -0
- package/android/build.gradle +69 -0
- package/android/src/main/AndroidManifest.xml +53 -0
- package/android/src/main/java/com/bggeolocation/BgGeolocationActivityRecognitionReceiver.kt +116 -0
- package/android/src/main/java/com/bggeolocation/BgGeolocationBootReceiver.kt +44 -0
- package/android/src/main/java/com/bggeolocation/BgGeolocationForegroundService.kt +373 -0
- package/android/src/main/java/com/bggeolocation/BgGeolocationGeofenceReceiver.kt +55 -0
- package/android/src/main/java/com/bggeolocation/BgGeolocationHeadlessTask.kt +138 -0
- package/android/src/main/java/com/bggeolocation/BgGeolocationModule.kt +1030 -0
- package/android/src/main/java/com/bggeolocation/BgGeolocationMotionStateMachine.kt +159 -0
- package/android/src/main/java/com/bggeolocation/BgGeolocationPackage.kt +31 -0
- package/android/src/main/res/drawable/bg_geo_notification.xml +9 -0
- package/ios/BgGeolocation.h +14 -0
- package/ios/BgGeolocation.mm +709 -0
- package/ios/engine/AtomicBoolean.swift +48 -0
- package/ios/engine/BGActivityChangeEvent.swift +20 -0
- package/ios/engine/BGActivityConfig.swift +71 -0
- package/ios/engine/BGAppConfig.swift +92 -0
- package/ios/engine/BGAppState.swift +147 -0
- package/ios/engine/BGAuthorization.swift +85 -0
- package/ios/engine/BGAuthorizationAlertPresenter.swift +39 -0
- package/ios/engine/BGAuthorizationConfig.swift +50 -0
- package/ios/engine/BGAuthorizationEvent.swift +40 -0
- package/ios/engine/BGBackgroundTaskManager.swift +143 -0
- package/ios/engine/BGCLRouter.swift +101 -0
- package/ios/engine/BGCallback.swift +19 -0
- package/ios/engine/BGConfig.swift +440 -0
- package/ios/engine/BGConfigModuleBase.swift +180 -0
- package/ios/engine/BGConfigOLD.swift +582 -0
- package/ios/engine/BGConnectivityChangeEvent.swift +15 -0
- package/ios/engine/BGCrashDetector.swift +122 -0
- package/ios/engine/BGCurrentPositionRequest.swift +87 -0
- package/ios/engine/BGDataStore.swift +75 -0
- package/ios/engine/BGDatabase.swift +677 -0
- package/ios/engine/BGDatabasePool.swift +220 -0
- package/ios/engine/BGDatabaseQueue.swift +215 -0
- package/ios/engine/BGDateUtils.swift +26 -0
- package/ios/engine/BGDeviceInfo.swift +54 -0
- package/ios/engine/BGDeviceManager.swift +65 -0
- package/ios/engine/BGEnabledChangeEvent.swift +11 -0
- package/ios/engine/BGEnv.swift +17 -0
- package/ios/engine/BGEventBus.swift +83 -0
- package/ios/engine/BGEventManager.swift +169 -0
- package/ios/engine/BGEventNames.swift +51 -0
- package/ios/engine/BGGeofence.swift +233 -0
- package/ios/engine/BGGeofenceDAO.swift +152 -0
- package/ios/engine/BGGeofenceEvent.swift +42 -0
- package/ios/engine/BGGeofenceLocationRequest.swift +94 -0
- package/ios/engine/BGGeofenceManager.swift +315 -0
- package/ios/engine/BGGeofenceTransition.swift +97 -0
- package/ios/engine/BGGeofencesChangeEvent.swift +26 -0
- package/ios/engine/BGGeolocationConfig.swift +136 -0
- package/ios/engine/BGHeartbeatEvent.swift +31 -0
- package/ios/engine/BGHeartbeatService.swift +51 -0
- package/ios/engine/BGHttpConfig.swift +105 -0
- package/ios/engine/BGHttpErrorCodes.swift +63 -0
- package/ios/engine/BGHttpEvent.swift +34 -0
- package/ios/engine/BGHttpRequest.swift +126 -0
- package/ios/engine/BGHttpResponse.swift +93 -0
- package/ios/engine/BGHttpService.swift +428 -0
- package/ios/engine/BGKalmanFilter.swift +105 -0
- package/ios/engine/BGLMActionNames.swift +55 -0
- package/ios/engine/BGLicenseManager.swift +26 -0
- package/ios/engine/BGLiveActivityManager.swift +327 -0
- package/ios/engine/BGLocation.swift +311 -0
- package/ios/engine/BGLocationAuthorization.swift +427 -0
- package/ios/engine/BGLocationDAO.swift +252 -0
- package/ios/engine/BGLocationErrors.swift +28 -0
- package/ios/engine/BGLocationEvent.swift +43 -0
- package/ios/engine/BGLocationFilter.swift +82 -0
- package/ios/engine/BGLocationFilterConfig.swift +57 -0
- package/ios/engine/BGLocationHelper.swift +54 -0
- package/ios/engine/BGLocationManager.swift +662 -0
- package/ios/engine/BGLocationMetricsEngine.swift +116 -0
- package/ios/engine/BGLocationRequestService.swift +459 -0
- package/ios/engine/BGLocationSatisfier.swift +14 -0
- package/ios/engine/BGLocationStreamEvent.swift +27 -0
- package/ios/engine/BGLog.swift +337 -0
- package/ios/engine/BGLogLevel.swift +26 -0
- package/ios/engine/BGLoggerConfig.swift +60 -0
- package/ios/engine/BGMotionActivity.swift +31 -0
- package/ios/engine/BGMotionActivityClassifier.swift +108 -0
- package/ios/engine/BGMotionActivityManagerAdapter.swift +40 -0
- package/ios/engine/BGMotionActivitySource.swift +46 -0
- package/ios/engine/BGMotionDetector.swift +377 -0
- package/ios/engine/BGMotionPermissionManager.swift +50 -0
- package/ios/engine/BGNativeLogger.swift +48 -0
- package/ios/engine/BGNotificaitons.swift +37 -0
- package/ios/engine/BGOdometer.swift +66 -0
- package/ios/engine/BGPersistenceConfig.swift +29 -0
- package/ios/engine/BGPolygonStreamRequest.swift +48 -0
- package/ios/engine/BGPowerSaveChangeEvent.swift +12 -0
- package/ios/engine/BGPropertySpec.swift +29 -0
- package/ios/engine/BGProviderChangeEvent.swift +31 -0
- package/ios/engine/BGQueue.swift +50 -0
- package/ios/engine/BGRPC.swift +194 -0
- package/ios/engine/BGReachability.swift +58 -0
- package/ios/engine/BGResultSet.swift +157 -0
- package/ios/engine/BGSchedule.swift +228 -0
- package/ios/engine/BGScheduleEvent.swift +13 -0
- package/ios/engine/BGScheduler.swift +116 -0
- package/ios/engine/BGSingleLocationRequest.swift +49 -0
- package/ios/engine/BGStreamLocationRequest.swift +42 -0
- package/ios/engine/BGTemplate.swift +54 -0
- package/ios/engine/BGTimerService.swift +46 -0
- package/ios/engine/BGTrackingAudioManager.swift +286 -0
- package/ios/engine/BGTrackingService.swift +879 -0
- package/ios/engine/BGWatchPositionRequest.swift +63 -0
- package/ios/engine/DatabaseQueue.swift +47 -0
- package/ios/engine/LogQuery.swift +10 -0
- package/ios/engine/SQLQuery.swift +65 -0
- package/ios/engine/TransistorAuthorizationToken.swift +182 -0
- package/ios/liveactivity/BGLiveTrackingAttributes.swift +52 -0
- package/ios/locationpush/BGLocationPushDeliverer.swift +260 -0
- package/ios/locationpush/BGLocationPushService.swift +161 -0
- package/ios/locationpush/BGLocationPushShared.swift +98 -0
- package/ios/locationpush/BGLocationPushSocketClient.swift +198 -0
- package/lib/module/NativeBgGeolocation.js +5 -0
- package/lib/module/NativeBgGeolocation.js.map +1 -0
- package/lib/module/events.js +20 -0
- package/lib/module/events.js.map +1 -0
- package/lib/module/index.js +706 -0
- package/lib/module/index.js.map +1 -0
- package/lib/module/package.json +1 -0
- package/lib/module/types.js +2 -0
- package/lib/module/types.js.map +1 -0
- package/lib/typescript/package.json +1 -0
- package/lib/typescript/src/NativeBgGeolocation.d.ts +57 -0
- package/lib/typescript/src/NativeBgGeolocation.d.ts.map +1 -0
- package/lib/typescript/src/events.d.ts +18 -0
- package/lib/typescript/src/events.d.ts.map +1 -0
- package/lib/typescript/src/index.d.ts +238 -0
- package/lib/typescript/src/index.d.ts.map +1 -0
- package/lib/typescript/src/types.d.ts +229 -0
- package/lib/typescript/src/types.d.ts.map +1 -0
- package/package.json +141 -0
- package/src/NativeBgGeolocation.ts +236 -0
- package/src/events.ts +17 -0
- package/src/index.tsx +935 -0
- package/src/types.ts +254 -0
package/src/index.tsx
ADDED
|
@@ -0,0 +1,935 @@
|
|
|
1
|
+
import { NativeEventEmitter, AppRegistry, Platform } from 'react-native';
|
|
2
|
+
import NativeBgGeolocation from './NativeBgGeolocation';
|
|
3
|
+
import * as Events from './events';
|
|
4
|
+
|
|
5
|
+
export type {
|
|
6
|
+
Location,
|
|
7
|
+
LocationError,
|
|
8
|
+
Geofence,
|
|
9
|
+
GeofenceEvent,
|
|
10
|
+
MotionChangeEvent,
|
|
11
|
+
HeartbeatEvent,
|
|
12
|
+
HeadlessEvent,
|
|
13
|
+
HttpEvent,
|
|
14
|
+
ProviderChangeEvent,
|
|
15
|
+
ActivityChangeEvent,
|
|
16
|
+
Subscription,
|
|
17
|
+
Config,
|
|
18
|
+
GeolocationConfig,
|
|
19
|
+
AppConfig,
|
|
20
|
+
LoggerConfig,
|
|
21
|
+
PersistenceConfig,
|
|
22
|
+
LiveActivityState,
|
|
23
|
+
NotificationConfig,
|
|
24
|
+
State,
|
|
25
|
+
DeviceInfo,
|
|
26
|
+
Sensors,
|
|
27
|
+
} from './types';
|
|
28
|
+
|
|
29
|
+
export { Events };
|
|
30
|
+
|
|
31
|
+
const EventEmitter = new NativeEventEmitter(NativeBgGeolocation as any);
|
|
32
|
+
|
|
33
|
+
const TAG = 'BackgroundGeolocation';
|
|
34
|
+
|
|
35
|
+
// Log levels
|
|
36
|
+
const LOG_LEVEL_OFF = 0;
|
|
37
|
+
const LOG_LEVEL_ERROR = 1;
|
|
38
|
+
const LOG_LEVEL_WARNING = 2;
|
|
39
|
+
const LOG_LEVEL_INFO = 3;
|
|
40
|
+
const LOG_LEVEL_DEBUG = 4;
|
|
41
|
+
const LOG_LEVEL_VERBOSE = 5;
|
|
42
|
+
|
|
43
|
+
// Accuracy
|
|
44
|
+
const DESIRED_ACCURACY_NAVIGATION = -2;
|
|
45
|
+
const DESIRED_ACCURACY_HIGH = -1;
|
|
46
|
+
const DESIRED_ACCURACY_MEDIUM = 10;
|
|
47
|
+
const DESIRED_ACCURACY_LOW = 100;
|
|
48
|
+
const DESIRED_ACCURACY_VERY_LOW = 1000;
|
|
49
|
+
const DESIRED_ACCURACY_LOWEST = 3000;
|
|
50
|
+
|
|
51
|
+
// Authorization status
|
|
52
|
+
const AUTHORIZATION_STATUS_NOT_DETERMINED = 0;
|
|
53
|
+
const AUTHORIZATION_STATUS_RESTRICTED = 1;
|
|
54
|
+
const AUTHORIZATION_STATUS_DENIED = 2;
|
|
55
|
+
const AUTHORIZATION_STATUS_ALWAYS = 3;
|
|
56
|
+
const AUTHORIZATION_STATUS_WHEN_IN_USE = 4;
|
|
57
|
+
|
|
58
|
+
// Notification priority
|
|
59
|
+
const NOTIFICATION_PRIORITY_DEFAULT = 0;
|
|
60
|
+
const NOTIFICATION_PRIORITY_HIGH = 1;
|
|
61
|
+
const NOTIFICATION_PRIORITY_LOW = -1;
|
|
62
|
+
const NOTIFICATION_PRIORITY_MAX = 2;
|
|
63
|
+
const NOTIFICATION_PRIORITY_MIN = -2;
|
|
64
|
+
|
|
65
|
+
// Activity type
|
|
66
|
+
const ACTIVITY_TYPE_OTHER = 1;
|
|
67
|
+
const ACTIVITY_TYPE_AUTOMOTIVE_NAVIGATION = 2;
|
|
68
|
+
const ACTIVITY_TYPE_FITNESS = 3;
|
|
69
|
+
const ACTIVITY_TYPE_OTHER_NAVIGATION = 4;
|
|
70
|
+
|
|
71
|
+
// Location authorization
|
|
72
|
+
const LOCATION_AUTHORIZATION_ALWAYS = 'Always';
|
|
73
|
+
const LOCATION_AUTHORIZATION_WHEN_IN_USE = 'WhenInUse';
|
|
74
|
+
const LOCATION_AUTHORIZATION_ANY = 'Any';
|
|
75
|
+
|
|
76
|
+
// Persist mode
|
|
77
|
+
const PERSIST_MODE_ALL = 2;
|
|
78
|
+
const PERSIST_MODE_LOCATION = 1;
|
|
79
|
+
const PERSIST_MODE_GEOFENCE = -1;
|
|
80
|
+
const PERSIST_MODE_NONE = 0;
|
|
81
|
+
|
|
82
|
+
// Accuracy authorization
|
|
83
|
+
const ACCURACY_AUTHORIZATION_FULL = 0;
|
|
84
|
+
const ACCURACY_AUTHORIZATION_REDUCED = 1;
|
|
85
|
+
|
|
86
|
+
interface Subscription {
|
|
87
|
+
remove(): void;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
let eventSubscriptions: Array<{
|
|
91
|
+
event: string;
|
|
92
|
+
subscription: any;
|
|
93
|
+
callback: Function;
|
|
94
|
+
}> = [];
|
|
95
|
+
|
|
96
|
+
const findByEventAndCallback = (event: string, callback: Function) => {
|
|
97
|
+
return (
|
|
98
|
+
eventSubscriptions.find(
|
|
99
|
+
(s) => s.event === event && s.callback === callback
|
|
100
|
+
) ?? null
|
|
101
|
+
);
|
|
102
|
+
};
|
|
103
|
+
|
|
104
|
+
const removeSubscription = (subscription: any) => {
|
|
105
|
+
const idx = eventSubscriptions.findIndex(
|
|
106
|
+
(s) => s.subscription === subscription
|
|
107
|
+
);
|
|
108
|
+
if (idx !== -1) eventSubscriptions.splice(idx, 1);
|
|
109
|
+
};
|
|
110
|
+
|
|
111
|
+
/**
|
|
112
|
+
* Flatten the modern nested Config shape
|
|
113
|
+
* { geolocation: {...}, app: {...}, logger: {...}, persistence: {...} }
|
|
114
|
+
* into the flat key/value map the native module consumes.
|
|
115
|
+
* Flat keys passed directly are preserved (legacy support).
|
|
116
|
+
*/
|
|
117
|
+
const flattenConfig = (
|
|
118
|
+
config: Record<string, any> = {}
|
|
119
|
+
): Record<string, any> => {
|
|
120
|
+
const out: Record<string, any> = {};
|
|
121
|
+
const nestedKeys = ['geolocation', 'app', 'logger', 'persistence'];
|
|
122
|
+
|
|
123
|
+
// Copy top-level keys — exclude nested section containers but KEEP `reset`
|
|
124
|
+
// so the native ready() can honour it (reset:false avoids wiping persisted
|
|
125
|
+
// config on kill-state relaunches, which would destroy stopOnTerminate etc.)
|
|
126
|
+
Object.keys(config).forEach((key) => {
|
|
127
|
+
if (!nestedKeys.includes(key)) {
|
|
128
|
+
out[key] = config[key];
|
|
129
|
+
}
|
|
130
|
+
});
|
|
131
|
+
|
|
132
|
+
// Spread each nested section onto the flat object
|
|
133
|
+
nestedKeys.forEach((section) => {
|
|
134
|
+
const sub = config[section];
|
|
135
|
+
if (sub && typeof sub === 'object') {
|
|
136
|
+
Object.assign(out, sub);
|
|
137
|
+
}
|
|
138
|
+
});
|
|
139
|
+
|
|
140
|
+
return out;
|
|
141
|
+
};
|
|
142
|
+
|
|
143
|
+
const validateConfig = (rawConfig: Record<string, any> = {}) => {
|
|
144
|
+
const config = flattenConfig(rawConfig);
|
|
145
|
+
|
|
146
|
+
if (
|
|
147
|
+
config.notificationPriority ||
|
|
148
|
+
config.notificationText ||
|
|
149
|
+
config.notificationTitle ||
|
|
150
|
+
config.notificationChannelName ||
|
|
151
|
+
config.notificationColor ||
|
|
152
|
+
config.notificationSmallIcon ||
|
|
153
|
+
config.notificationLargeIcon
|
|
154
|
+
) {
|
|
155
|
+
console.warn(
|
|
156
|
+
`[${TAG}] WARNING: notification* fields are deprecated. Use notification: {title, text, ...}`
|
|
157
|
+
);
|
|
158
|
+
config.notification = {
|
|
159
|
+
text: config.notificationText,
|
|
160
|
+
title: config.notificationTitle,
|
|
161
|
+
color: config.notificationColor,
|
|
162
|
+
channelName: config.notificationChannelName,
|
|
163
|
+
smallIcon: config.notificationSmallIcon,
|
|
164
|
+
largeIcon: config.notificationLargeIcon,
|
|
165
|
+
priority: config.notificationPriority,
|
|
166
|
+
};
|
|
167
|
+
}
|
|
168
|
+
return config;
|
|
169
|
+
};
|
|
170
|
+
|
|
171
|
+
const logger = {
|
|
172
|
+
error: (msg: string) => NativeBgGeolocation.log('error', msg),
|
|
173
|
+
warn: (msg: string) => NativeBgGeolocation.log('warn', msg),
|
|
174
|
+
debug: (msg: string) => NativeBgGeolocation.log('debug', msg),
|
|
175
|
+
info: (msg: string) => NativeBgGeolocation.log('info', msg),
|
|
176
|
+
notice: (msg: string) => NativeBgGeolocation.log('notice', msg),
|
|
177
|
+
header: (msg: string) => NativeBgGeolocation.log('header', msg),
|
|
178
|
+
on: (msg: string) => NativeBgGeolocation.log('on', msg),
|
|
179
|
+
off: (msg: string) => NativeBgGeolocation.log('off', msg),
|
|
180
|
+
ok: (msg: string) => NativeBgGeolocation.log('ok', msg),
|
|
181
|
+
getLog: () =>
|
|
182
|
+
new Promise<string>((resolve, reject) =>
|
|
183
|
+
NativeBgGeolocation.getLog(resolve, reject)
|
|
184
|
+
),
|
|
185
|
+
destroyLog: () =>
|
|
186
|
+
new Promise<void>((resolve, reject) =>
|
|
187
|
+
NativeBgGeolocation.destroyLog(resolve, reject)
|
|
188
|
+
),
|
|
189
|
+
emailLog: (email: string) =>
|
|
190
|
+
new Promise<void>((resolve, reject) =>
|
|
191
|
+
NativeBgGeolocation.emailLog(email, resolve, reject)
|
|
192
|
+
),
|
|
193
|
+
};
|
|
194
|
+
|
|
195
|
+
export default class BackgroundGeolocation {
|
|
196
|
+
// ─── Constants ────────────────────────────────────────────────────────────
|
|
197
|
+
static get EVENT_BOOT() {
|
|
198
|
+
return Events.BOOT;
|
|
199
|
+
}
|
|
200
|
+
static get EVENT_TERMINATE() {
|
|
201
|
+
return Events.TERMINATE;
|
|
202
|
+
}
|
|
203
|
+
static get EVENT_LOCATION() {
|
|
204
|
+
return Events.LOCATION;
|
|
205
|
+
}
|
|
206
|
+
static get EVENT_MOTIONCHANGE() {
|
|
207
|
+
return Events.MOTIONCHANGE;
|
|
208
|
+
}
|
|
209
|
+
static get EVENT_HTTP() {
|
|
210
|
+
return Events.HTTP;
|
|
211
|
+
}
|
|
212
|
+
static get EVENT_HEARTBEAT() {
|
|
213
|
+
return Events.HEARTBEAT;
|
|
214
|
+
}
|
|
215
|
+
static get EVENT_PROVIDERCHANGE() {
|
|
216
|
+
return Events.PROVIDERCHANGE;
|
|
217
|
+
}
|
|
218
|
+
static get EVENT_ACTIVITYCHANGE() {
|
|
219
|
+
return Events.ACTIVITYCHANGE;
|
|
220
|
+
}
|
|
221
|
+
static get EVENT_GEOFENCE() {
|
|
222
|
+
return Events.GEOFENCE;
|
|
223
|
+
}
|
|
224
|
+
static get EVENT_GEOFENCESCHANGE() {
|
|
225
|
+
return Events.GEOFENCESCHANGE;
|
|
226
|
+
}
|
|
227
|
+
static get EVENT_ENABLEDCHANGE() {
|
|
228
|
+
return Events.ENABLEDCHANGE;
|
|
229
|
+
}
|
|
230
|
+
static get EVENT_CONNECTIVITYCHANGE() {
|
|
231
|
+
return Events.CONNECTIVITYCHANGE;
|
|
232
|
+
}
|
|
233
|
+
static get EVENT_SCHEDULE() {
|
|
234
|
+
return Events.SCHEDULE;
|
|
235
|
+
}
|
|
236
|
+
static get EVENT_POWERSAVECHANGE() {
|
|
237
|
+
return Events.POWERSAVECHANGE;
|
|
238
|
+
}
|
|
239
|
+
static get EVENT_NOTIFICATIONACTION() {
|
|
240
|
+
return Events.NOTIFICATIONACTION;
|
|
241
|
+
}
|
|
242
|
+
static get EVENT_AUTHORIZATION() {
|
|
243
|
+
return Events.AUTHORIZATION;
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
static get LOG_LEVEL_OFF() {
|
|
247
|
+
return LOG_LEVEL_OFF;
|
|
248
|
+
}
|
|
249
|
+
static get LOG_LEVEL_ERROR() {
|
|
250
|
+
return LOG_LEVEL_ERROR;
|
|
251
|
+
}
|
|
252
|
+
static get LOG_LEVEL_WARNING() {
|
|
253
|
+
return LOG_LEVEL_WARNING;
|
|
254
|
+
}
|
|
255
|
+
static get LOG_LEVEL_INFO() {
|
|
256
|
+
return LOG_LEVEL_INFO;
|
|
257
|
+
}
|
|
258
|
+
static get LOG_LEVEL_DEBUG() {
|
|
259
|
+
return LOG_LEVEL_DEBUG;
|
|
260
|
+
}
|
|
261
|
+
static get LOG_LEVEL_VERBOSE() {
|
|
262
|
+
return LOG_LEVEL_VERBOSE;
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
static get DESIRED_ACCURACY_NAVIGATION() {
|
|
266
|
+
return DESIRED_ACCURACY_NAVIGATION;
|
|
267
|
+
}
|
|
268
|
+
static get DESIRED_ACCURACY_HIGH() {
|
|
269
|
+
return DESIRED_ACCURACY_HIGH;
|
|
270
|
+
}
|
|
271
|
+
static get DESIRED_ACCURACY_MEDIUM() {
|
|
272
|
+
return DESIRED_ACCURACY_MEDIUM;
|
|
273
|
+
}
|
|
274
|
+
static get DESIRED_ACCURACY_LOW() {
|
|
275
|
+
return DESIRED_ACCURACY_LOW;
|
|
276
|
+
}
|
|
277
|
+
static get DESIRED_ACCURACY_VERY_LOW() {
|
|
278
|
+
return DESIRED_ACCURACY_VERY_LOW;
|
|
279
|
+
}
|
|
280
|
+
static get DESIRED_ACCURACY_LOWEST() {
|
|
281
|
+
return DESIRED_ACCURACY_LOWEST;
|
|
282
|
+
}
|
|
283
|
+
|
|
284
|
+
static get AUTHORIZATION_STATUS_NOT_DETERMINED() {
|
|
285
|
+
return AUTHORIZATION_STATUS_NOT_DETERMINED;
|
|
286
|
+
}
|
|
287
|
+
static get AUTHORIZATION_STATUS_RESTRICTED() {
|
|
288
|
+
return AUTHORIZATION_STATUS_RESTRICTED;
|
|
289
|
+
}
|
|
290
|
+
static get AUTHORIZATION_STATUS_DENIED() {
|
|
291
|
+
return AUTHORIZATION_STATUS_DENIED;
|
|
292
|
+
}
|
|
293
|
+
static get AUTHORIZATION_STATUS_ALWAYS() {
|
|
294
|
+
return AUTHORIZATION_STATUS_ALWAYS;
|
|
295
|
+
}
|
|
296
|
+
static get AUTHORIZATION_STATUS_WHEN_IN_USE() {
|
|
297
|
+
return AUTHORIZATION_STATUS_WHEN_IN_USE;
|
|
298
|
+
}
|
|
299
|
+
|
|
300
|
+
static get NOTIFICATION_PRIORITY_DEFAULT() {
|
|
301
|
+
return NOTIFICATION_PRIORITY_DEFAULT;
|
|
302
|
+
}
|
|
303
|
+
static get NOTIFICATION_PRIORITY_HIGH() {
|
|
304
|
+
return NOTIFICATION_PRIORITY_HIGH;
|
|
305
|
+
}
|
|
306
|
+
static get NOTIFICATION_PRIORITY_LOW() {
|
|
307
|
+
return NOTIFICATION_PRIORITY_LOW;
|
|
308
|
+
}
|
|
309
|
+
static get NOTIFICATION_PRIORITY_MAX() {
|
|
310
|
+
return NOTIFICATION_PRIORITY_MAX;
|
|
311
|
+
}
|
|
312
|
+
static get NOTIFICATION_PRIORITY_MIN() {
|
|
313
|
+
return NOTIFICATION_PRIORITY_MIN;
|
|
314
|
+
}
|
|
315
|
+
|
|
316
|
+
static get ACTIVITY_TYPE_OTHER() {
|
|
317
|
+
return ACTIVITY_TYPE_OTHER;
|
|
318
|
+
}
|
|
319
|
+
static get ACTIVITY_TYPE_AUTOMOTIVE_NAVIGATION() {
|
|
320
|
+
return ACTIVITY_TYPE_AUTOMOTIVE_NAVIGATION;
|
|
321
|
+
}
|
|
322
|
+
static get ACTIVITY_TYPE_FITNESS() {
|
|
323
|
+
return ACTIVITY_TYPE_FITNESS;
|
|
324
|
+
}
|
|
325
|
+
static get ACTIVITY_TYPE_OTHER_NAVIGATION() {
|
|
326
|
+
return ACTIVITY_TYPE_OTHER_NAVIGATION;
|
|
327
|
+
}
|
|
328
|
+
|
|
329
|
+
static get LOCATION_AUTHORIZATION_ALWAYS() {
|
|
330
|
+
return LOCATION_AUTHORIZATION_ALWAYS;
|
|
331
|
+
}
|
|
332
|
+
static get LOCATION_AUTHORIZATION_WHEN_IN_USE() {
|
|
333
|
+
return LOCATION_AUTHORIZATION_WHEN_IN_USE;
|
|
334
|
+
}
|
|
335
|
+
static get LOCATION_AUTHORIZATION_ANY() {
|
|
336
|
+
return LOCATION_AUTHORIZATION_ANY;
|
|
337
|
+
}
|
|
338
|
+
|
|
339
|
+
static get PERSIST_MODE_ALL() {
|
|
340
|
+
return PERSIST_MODE_ALL;
|
|
341
|
+
}
|
|
342
|
+
static get PERSIST_MODE_LOCATION() {
|
|
343
|
+
return PERSIST_MODE_LOCATION;
|
|
344
|
+
}
|
|
345
|
+
static get PERSIST_MODE_GEOFENCE() {
|
|
346
|
+
return PERSIST_MODE_GEOFENCE;
|
|
347
|
+
}
|
|
348
|
+
static get PERSIST_MODE_NONE() {
|
|
349
|
+
return PERSIST_MODE_NONE;
|
|
350
|
+
}
|
|
351
|
+
|
|
352
|
+
static get ACCURACY_AUTHORIZATION_FULL() {
|
|
353
|
+
return ACCURACY_AUTHORIZATION_FULL;
|
|
354
|
+
}
|
|
355
|
+
static get ACCURACY_AUTHORIZATION_REDUCED() {
|
|
356
|
+
return ACCURACY_AUTHORIZATION_REDUCED;
|
|
357
|
+
}
|
|
358
|
+
|
|
359
|
+
// ─── Namespaced enums (match react-native-background-geolocation) ───────────
|
|
360
|
+
static get AuthorizationStatus() {
|
|
361
|
+
return {
|
|
362
|
+
NotDetermined: AUTHORIZATION_STATUS_NOT_DETERMINED,
|
|
363
|
+
Restricted: AUTHORIZATION_STATUS_RESTRICTED,
|
|
364
|
+
Denied: AUTHORIZATION_STATUS_DENIED,
|
|
365
|
+
Always: AUTHORIZATION_STATUS_ALWAYS,
|
|
366
|
+
WhenInUse: AUTHORIZATION_STATUS_WHEN_IN_USE,
|
|
367
|
+
} as const;
|
|
368
|
+
}
|
|
369
|
+
|
|
370
|
+
static get DesiredAccuracy() {
|
|
371
|
+
return {
|
|
372
|
+
Navigation: DESIRED_ACCURACY_NAVIGATION,
|
|
373
|
+
High: DESIRED_ACCURACY_HIGH,
|
|
374
|
+
Medium: DESIRED_ACCURACY_MEDIUM,
|
|
375
|
+
Low: DESIRED_ACCURACY_LOW,
|
|
376
|
+
VeryLow: DESIRED_ACCURACY_VERY_LOW,
|
|
377
|
+
Lowest: DESIRED_ACCURACY_LOWEST,
|
|
378
|
+
} as const;
|
|
379
|
+
}
|
|
380
|
+
|
|
381
|
+
static get LogLevel() {
|
|
382
|
+
return {
|
|
383
|
+
Off: LOG_LEVEL_OFF,
|
|
384
|
+
Error: LOG_LEVEL_ERROR,
|
|
385
|
+
Warning: LOG_LEVEL_WARNING,
|
|
386
|
+
Info: LOG_LEVEL_INFO,
|
|
387
|
+
Debug: LOG_LEVEL_DEBUG,
|
|
388
|
+
Verbose: LOG_LEVEL_VERBOSE,
|
|
389
|
+
} as const;
|
|
390
|
+
}
|
|
391
|
+
|
|
392
|
+
static get NotificationPriority() {
|
|
393
|
+
return {
|
|
394
|
+
Default: NOTIFICATION_PRIORITY_DEFAULT,
|
|
395
|
+
High: NOTIFICATION_PRIORITY_HIGH,
|
|
396
|
+
Low: NOTIFICATION_PRIORITY_LOW,
|
|
397
|
+
Max: NOTIFICATION_PRIORITY_MAX,
|
|
398
|
+
Min: NOTIFICATION_PRIORITY_MIN,
|
|
399
|
+
} as const;
|
|
400
|
+
}
|
|
401
|
+
|
|
402
|
+
static get ActivityType() {
|
|
403
|
+
return {
|
|
404
|
+
Other: ACTIVITY_TYPE_OTHER,
|
|
405
|
+
AutomotiveNavigation: ACTIVITY_TYPE_AUTOMOTIVE_NAVIGATION,
|
|
406
|
+
Fitness: ACTIVITY_TYPE_FITNESS,
|
|
407
|
+
OtherNavigation: ACTIVITY_TYPE_OTHER_NAVIGATION,
|
|
408
|
+
} as const;
|
|
409
|
+
}
|
|
410
|
+
|
|
411
|
+
static get PersistMode() {
|
|
412
|
+
return {
|
|
413
|
+
All: PERSIST_MODE_ALL,
|
|
414
|
+
Location: PERSIST_MODE_LOCATION,
|
|
415
|
+
Geofence: PERSIST_MODE_GEOFENCE,
|
|
416
|
+
None: PERSIST_MODE_NONE,
|
|
417
|
+
} as const;
|
|
418
|
+
}
|
|
419
|
+
|
|
420
|
+
static get AccuracyAuthorization() {
|
|
421
|
+
return {
|
|
422
|
+
Full: ACCURACY_AUTHORIZATION_FULL,
|
|
423
|
+
Reduced: ACCURACY_AUTHORIZATION_REDUCED,
|
|
424
|
+
} as const;
|
|
425
|
+
}
|
|
426
|
+
|
|
427
|
+
static get logger() {
|
|
428
|
+
return logger;
|
|
429
|
+
}
|
|
430
|
+
|
|
431
|
+
// ─── Headless Task ────────────────────────────────────────────────────────
|
|
432
|
+
static registerHeadlessTask(task: Function) {
|
|
433
|
+
AppRegistry.registerHeadlessTask(TAG, () => task as any);
|
|
434
|
+
}
|
|
435
|
+
|
|
436
|
+
// ─── Core ─────────────────────────────────────────────────────────────────
|
|
437
|
+
static ready(config: Record<string, any> = {}): Promise<any> {
|
|
438
|
+
return new Promise((resolve, reject) =>
|
|
439
|
+
NativeBgGeolocation.ready(validateConfig(config), resolve, reject)
|
|
440
|
+
);
|
|
441
|
+
}
|
|
442
|
+
|
|
443
|
+
static configure(config: Record<string, any> = {}): Promise<any> {
|
|
444
|
+
console.warn(`[${TAG}] #configure is deprecated. Use #ready`);
|
|
445
|
+
return new Promise((resolve, reject) =>
|
|
446
|
+
NativeBgGeolocation.configure(validateConfig(config), resolve, reject)
|
|
447
|
+
);
|
|
448
|
+
}
|
|
449
|
+
|
|
450
|
+
static reset(config: Record<string, any> = {}): Promise<any> {
|
|
451
|
+
return new Promise((resolve, reject) =>
|
|
452
|
+
NativeBgGeolocation.reset(validateConfig(config), resolve, reject)
|
|
453
|
+
);
|
|
454
|
+
}
|
|
455
|
+
|
|
456
|
+
static setConfig(config: Record<string, any>): Promise<any> {
|
|
457
|
+
return new Promise((resolve, reject) =>
|
|
458
|
+
NativeBgGeolocation.setConfig(validateConfig(config), resolve, reject)
|
|
459
|
+
);
|
|
460
|
+
}
|
|
461
|
+
|
|
462
|
+
static getState(): Promise<any> {
|
|
463
|
+
return new Promise((resolve, reject) =>
|
|
464
|
+
NativeBgGeolocation.getState(resolve, reject)
|
|
465
|
+
);
|
|
466
|
+
}
|
|
467
|
+
|
|
468
|
+
// ─── Lifecycle ────────────────────────────────────────────────────────────
|
|
469
|
+
static start(): Promise<any> {
|
|
470
|
+
return new Promise((resolve, reject) =>
|
|
471
|
+
NativeBgGeolocation.start(resolve, reject)
|
|
472
|
+
);
|
|
473
|
+
}
|
|
474
|
+
|
|
475
|
+
static stop(): Promise<any> {
|
|
476
|
+
return new Promise((resolve, reject) =>
|
|
477
|
+
NativeBgGeolocation.stop(resolve, reject)
|
|
478
|
+
);
|
|
479
|
+
}
|
|
480
|
+
|
|
481
|
+
static startSchedule(): Promise<any> {
|
|
482
|
+
return new Promise((resolve, reject) =>
|
|
483
|
+
NativeBgGeolocation.startSchedule(resolve, reject)
|
|
484
|
+
);
|
|
485
|
+
}
|
|
486
|
+
|
|
487
|
+
static stopSchedule(): Promise<any> {
|
|
488
|
+
return new Promise((resolve, reject) =>
|
|
489
|
+
NativeBgGeolocation.stopSchedule(resolve, reject)
|
|
490
|
+
);
|
|
491
|
+
}
|
|
492
|
+
|
|
493
|
+
static startGeofences(): Promise<any> {
|
|
494
|
+
return new Promise((resolve, reject) =>
|
|
495
|
+
NativeBgGeolocation.startGeofences(resolve, reject)
|
|
496
|
+
);
|
|
497
|
+
}
|
|
498
|
+
|
|
499
|
+
// ─── Background Task ──────────────────────────────────────────────────────
|
|
500
|
+
static startBackgroundTask(): Promise<number> {
|
|
501
|
+
return new Promise((resolve, reject) =>
|
|
502
|
+
NativeBgGeolocation.beginBackgroundTask(resolve, reject)
|
|
503
|
+
);
|
|
504
|
+
}
|
|
505
|
+
|
|
506
|
+
static stopBackgroundTask(taskId: number): Promise<number> {
|
|
507
|
+
return new Promise((resolve, reject) => {
|
|
508
|
+
if (!taskId) {
|
|
509
|
+
reject(`INVALID_TASK_ID: ${taskId}`);
|
|
510
|
+
return;
|
|
511
|
+
}
|
|
512
|
+
NativeBgGeolocation.finish(taskId, () => resolve(taskId), reject);
|
|
513
|
+
});
|
|
514
|
+
}
|
|
515
|
+
|
|
516
|
+
static finish(taskId: number): Promise<number> {
|
|
517
|
+
return BackgroundGeolocation.stopBackgroundTask(taskId);
|
|
518
|
+
}
|
|
519
|
+
|
|
520
|
+
// ─── Motion / Location ────────────────────────────────────────────────────
|
|
521
|
+
static changePace(isMoving: boolean): Promise<void> {
|
|
522
|
+
return new Promise((resolve, reject) =>
|
|
523
|
+
NativeBgGeolocation.changePace(isMoving, resolve, reject)
|
|
524
|
+
);
|
|
525
|
+
}
|
|
526
|
+
|
|
527
|
+
static getCurrentPosition(options: Record<string, any> = {}): Promise<any> {
|
|
528
|
+
if (typeof options === 'function') {
|
|
529
|
+
throw `${TAG}#getCurrentPosition requires options {} as first argument`;
|
|
530
|
+
}
|
|
531
|
+
return new Promise((resolve, reject) =>
|
|
532
|
+
NativeBgGeolocation.getCurrentPosition(options, resolve, reject)
|
|
533
|
+
);
|
|
534
|
+
}
|
|
535
|
+
|
|
536
|
+
static watchPosition(
|
|
537
|
+
success: Function,
|
|
538
|
+
failure?: Function,
|
|
539
|
+
options: Record<string, any> = {}
|
|
540
|
+
): void {
|
|
541
|
+
if (!success) {
|
|
542
|
+
throw `${TAG}#watchPosition cannot use Promises — supply a callback`;
|
|
543
|
+
}
|
|
544
|
+
const cb = () => EventEmitter.addListener('watchposition', success as any);
|
|
545
|
+
NativeBgGeolocation.watchPosition(
|
|
546
|
+
options,
|
|
547
|
+
cb,
|
|
548
|
+
(failure ?? (() => {})) as (error: string) => void
|
|
549
|
+
);
|
|
550
|
+
}
|
|
551
|
+
|
|
552
|
+
static stopWatchPosition(): Promise<void> {
|
|
553
|
+
return new Promise((resolve, reject) => {
|
|
554
|
+
EventEmitter.removeAllListeners('watchposition');
|
|
555
|
+
NativeBgGeolocation.stopWatchPosition(resolve, reject);
|
|
556
|
+
});
|
|
557
|
+
}
|
|
558
|
+
|
|
559
|
+
// ─── Permissions ──────────────────────────────────────────────────────────
|
|
560
|
+
static requestPermission(): Promise<number> {
|
|
561
|
+
return new Promise((resolve, reject) =>
|
|
562
|
+
NativeBgGeolocation.requestPermission(resolve, reject)
|
|
563
|
+
);
|
|
564
|
+
}
|
|
565
|
+
|
|
566
|
+
static requestMotionPermission(): Promise<number> {
|
|
567
|
+
return new Promise((resolve, reject) =>
|
|
568
|
+
NativeBgGeolocation.requestMotionPermission(resolve, reject)
|
|
569
|
+
);
|
|
570
|
+
}
|
|
571
|
+
|
|
572
|
+
static requestTemporaryFullAccuracy(purpose: string): Promise<number> {
|
|
573
|
+
return new Promise((resolve, reject) =>
|
|
574
|
+
NativeBgGeolocation.requestTemporaryFullAccuracy(purpose, resolve, reject)
|
|
575
|
+
);
|
|
576
|
+
}
|
|
577
|
+
|
|
578
|
+
static getProviderState(): Promise<any> {
|
|
579
|
+
return new Promise((resolve, reject) =>
|
|
580
|
+
NativeBgGeolocation.getProviderState(resolve, reject)
|
|
581
|
+
);
|
|
582
|
+
}
|
|
583
|
+
|
|
584
|
+
// ─── HTTP & Persistence ───────────────────────────────────────────────────
|
|
585
|
+
static getLocations(): Promise<any[]> {
|
|
586
|
+
return new Promise((resolve, reject) =>
|
|
587
|
+
NativeBgGeolocation.getLocations(resolve, reject)
|
|
588
|
+
);
|
|
589
|
+
}
|
|
590
|
+
|
|
591
|
+
static getCount(): Promise<number> {
|
|
592
|
+
return new Promise((resolve, reject) =>
|
|
593
|
+
NativeBgGeolocation.getCount(resolve, reject)
|
|
594
|
+
);
|
|
595
|
+
}
|
|
596
|
+
|
|
597
|
+
static destroyLocations(): Promise<void> {
|
|
598
|
+
return new Promise((resolve, reject) =>
|
|
599
|
+
NativeBgGeolocation.destroyLocations(resolve, reject)
|
|
600
|
+
);
|
|
601
|
+
}
|
|
602
|
+
|
|
603
|
+
static destroyLocation(uuid: string): Promise<void> {
|
|
604
|
+
return new Promise((resolve, reject) =>
|
|
605
|
+
NativeBgGeolocation.destroyLocation(uuid, resolve, reject)
|
|
606
|
+
);
|
|
607
|
+
}
|
|
608
|
+
|
|
609
|
+
static insertLocation(location: Record<string, any>): Promise<any> {
|
|
610
|
+
return new Promise((resolve, reject) =>
|
|
611
|
+
NativeBgGeolocation.insertLocation(location, resolve, reject)
|
|
612
|
+
);
|
|
613
|
+
}
|
|
614
|
+
|
|
615
|
+
static sync(): Promise<any[]> {
|
|
616
|
+
return new Promise((resolve, reject) =>
|
|
617
|
+
NativeBgGeolocation.sync(resolve, reject)
|
|
618
|
+
);
|
|
619
|
+
}
|
|
620
|
+
|
|
621
|
+
// ─── Odometer ─────────────────────────────────────────────────────────────
|
|
622
|
+
static getOdometer(): Promise<number> {
|
|
623
|
+
return new Promise((resolve, reject) =>
|
|
624
|
+
NativeBgGeolocation.getOdometer(resolve, reject)
|
|
625
|
+
);
|
|
626
|
+
}
|
|
627
|
+
|
|
628
|
+
static setOdometer(value: number): Promise<any> {
|
|
629
|
+
return new Promise((resolve, reject) =>
|
|
630
|
+
NativeBgGeolocation.setOdometer(value, resolve, reject)
|
|
631
|
+
);
|
|
632
|
+
}
|
|
633
|
+
|
|
634
|
+
static resetOdometer(): Promise<any> {
|
|
635
|
+
return BackgroundGeolocation.setOdometer(0);
|
|
636
|
+
}
|
|
637
|
+
|
|
638
|
+
// ─── Geofences ────────────────────────────────────────────────────────────
|
|
639
|
+
static addGeofence(config: Record<string, any>): Promise<void> {
|
|
640
|
+
return new Promise((resolve, reject) =>
|
|
641
|
+
NativeBgGeolocation.addGeofence(config, resolve, reject)
|
|
642
|
+
);
|
|
643
|
+
}
|
|
644
|
+
|
|
645
|
+
static addGeofences(geofences: Record<string, any>[]): Promise<void> {
|
|
646
|
+
return new Promise((resolve, reject) =>
|
|
647
|
+
NativeBgGeolocation.addGeofences(geofences, resolve, reject)
|
|
648
|
+
);
|
|
649
|
+
}
|
|
650
|
+
|
|
651
|
+
static removeGeofence(identifier: string): Promise<void> {
|
|
652
|
+
return new Promise((resolve, reject) =>
|
|
653
|
+
NativeBgGeolocation.removeGeofence(identifier, resolve, reject)
|
|
654
|
+
);
|
|
655
|
+
}
|
|
656
|
+
|
|
657
|
+
static removeGeofences(): Promise<void> {
|
|
658
|
+
return new Promise((resolve, reject) =>
|
|
659
|
+
NativeBgGeolocation.removeGeofences(resolve, reject)
|
|
660
|
+
);
|
|
661
|
+
}
|
|
662
|
+
|
|
663
|
+
static getGeofences(): Promise<any[]> {
|
|
664
|
+
return new Promise((resolve, reject) =>
|
|
665
|
+
NativeBgGeolocation.getGeofences(resolve, reject)
|
|
666
|
+
);
|
|
667
|
+
}
|
|
668
|
+
|
|
669
|
+
static getGeofence(identifier: string): Promise<any> {
|
|
670
|
+
return new Promise((resolve, reject) => {
|
|
671
|
+
if (!identifier) {
|
|
672
|
+
reject(`Invalid identifier: ${identifier}`);
|
|
673
|
+
return;
|
|
674
|
+
}
|
|
675
|
+
NativeBgGeolocation.getGeofence(identifier, resolve, reject);
|
|
676
|
+
});
|
|
677
|
+
}
|
|
678
|
+
|
|
679
|
+
static geofenceExists(identifier: string): Promise<boolean> {
|
|
680
|
+
return new Promise((resolve, reject) => {
|
|
681
|
+
if (!identifier) {
|
|
682
|
+
reject(`Invalid identifier: ${identifier}`);
|
|
683
|
+
return;
|
|
684
|
+
}
|
|
685
|
+
NativeBgGeolocation.geofenceExists(identifier, resolve);
|
|
686
|
+
});
|
|
687
|
+
}
|
|
688
|
+
|
|
689
|
+
// ─── Event Listeners ──────────────────────────────────────────────────────
|
|
690
|
+
static addListener(
|
|
691
|
+
event: string,
|
|
692
|
+
success: Function,
|
|
693
|
+
failure?: Function
|
|
694
|
+
): Subscription {
|
|
695
|
+
if (typeof event !== 'string')
|
|
696
|
+
throw `${TAG}#addListener: event must be a string`;
|
|
697
|
+
const handler = (response: any) => {
|
|
698
|
+
if (response?.error != null) {
|
|
699
|
+
if (typeof failure === 'function') failure(response.error);
|
|
700
|
+
else success(response);
|
|
701
|
+
} else {
|
|
702
|
+
success(response);
|
|
703
|
+
}
|
|
704
|
+
};
|
|
705
|
+
const subscription = EventEmitter.addListener(event, handler);
|
|
706
|
+
const originalRemove = subscription.remove.bind(subscription);
|
|
707
|
+
subscription.remove = () => {
|
|
708
|
+
originalRemove();
|
|
709
|
+
removeSubscription(subscription);
|
|
710
|
+
};
|
|
711
|
+
eventSubscriptions.push({ event, subscription, callback: success });
|
|
712
|
+
return subscription;
|
|
713
|
+
}
|
|
714
|
+
|
|
715
|
+
static on(
|
|
716
|
+
event: string,
|
|
717
|
+
success: Function,
|
|
718
|
+
failure?: Function
|
|
719
|
+
): Subscription {
|
|
720
|
+
return BackgroundGeolocation.addListener(event, success, failure);
|
|
721
|
+
}
|
|
722
|
+
|
|
723
|
+
static removeListener(event: string, callback: Function): void {
|
|
724
|
+
const found = findByEventAndCallback(event, callback);
|
|
725
|
+
if (found) found.subscription.remove();
|
|
726
|
+
}
|
|
727
|
+
|
|
728
|
+
static un(event: string, callback: Function): void {
|
|
729
|
+
BackgroundGeolocation.removeListener(event, callback);
|
|
730
|
+
}
|
|
731
|
+
|
|
732
|
+
static removeListeners(): Promise<void> {
|
|
733
|
+
return new Promise((resolve) => {
|
|
734
|
+
eventSubscriptions.forEach((s) => s.subscription.remove());
|
|
735
|
+
eventSubscriptions = [];
|
|
736
|
+
resolve();
|
|
737
|
+
});
|
|
738
|
+
}
|
|
739
|
+
|
|
740
|
+
static removeAllListeners(): Promise<void> {
|
|
741
|
+
return BackgroundGeolocation.removeListeners();
|
|
742
|
+
}
|
|
743
|
+
|
|
744
|
+
// ─── Typed event helpers ──────────────────────────────────────────────────
|
|
745
|
+
static onLocation(success: Function, failure?: Function): Subscription {
|
|
746
|
+
return BackgroundGeolocation.addListener(Events.LOCATION, success, failure);
|
|
747
|
+
}
|
|
748
|
+
|
|
749
|
+
static onMotionChange(callback: Function): Subscription {
|
|
750
|
+
return BackgroundGeolocation.addListener(Events.MOTIONCHANGE, callback);
|
|
751
|
+
}
|
|
752
|
+
|
|
753
|
+
static onHttp(callback: Function): Subscription {
|
|
754
|
+
return BackgroundGeolocation.addListener(Events.HTTP, callback);
|
|
755
|
+
}
|
|
756
|
+
|
|
757
|
+
static onHeartbeat(callback: Function): Subscription {
|
|
758
|
+
return BackgroundGeolocation.addListener(Events.HEARTBEAT, callback);
|
|
759
|
+
}
|
|
760
|
+
|
|
761
|
+
static onProviderChange(callback: Function): Subscription {
|
|
762
|
+
return BackgroundGeolocation.addListener(Events.PROVIDERCHANGE, callback);
|
|
763
|
+
}
|
|
764
|
+
|
|
765
|
+
static onActivityChange(callback: Function): Subscription {
|
|
766
|
+
return BackgroundGeolocation.addListener(Events.ACTIVITYCHANGE, callback);
|
|
767
|
+
}
|
|
768
|
+
|
|
769
|
+
static onGeofence(callback: Function): Subscription {
|
|
770
|
+
return BackgroundGeolocation.addListener(Events.GEOFENCE, callback);
|
|
771
|
+
}
|
|
772
|
+
|
|
773
|
+
static onGeofencesChange(callback: Function): Subscription {
|
|
774
|
+
return BackgroundGeolocation.addListener(Events.GEOFENCESCHANGE, callback);
|
|
775
|
+
}
|
|
776
|
+
|
|
777
|
+
static onSchedule(callback: Function): Subscription {
|
|
778
|
+
return BackgroundGeolocation.addListener(Events.SCHEDULE, callback);
|
|
779
|
+
}
|
|
780
|
+
|
|
781
|
+
static onEnabledChange(callback: Function): Subscription {
|
|
782
|
+
return BackgroundGeolocation.addListener(Events.ENABLEDCHANGE, callback);
|
|
783
|
+
}
|
|
784
|
+
|
|
785
|
+
static onConnectivityChange(callback: Function): Subscription {
|
|
786
|
+
return BackgroundGeolocation.addListener(
|
|
787
|
+
Events.CONNECTIVITYCHANGE,
|
|
788
|
+
callback
|
|
789
|
+
);
|
|
790
|
+
}
|
|
791
|
+
|
|
792
|
+
static onPowerSaveChange(callback: Function): Subscription {
|
|
793
|
+
return BackgroundGeolocation.addListener(Events.POWERSAVECHANGE, callback);
|
|
794
|
+
}
|
|
795
|
+
|
|
796
|
+
static onNotificationAction(callback: Function): Subscription {
|
|
797
|
+
return BackgroundGeolocation.addListener(
|
|
798
|
+
Events.NOTIFICATIONACTION,
|
|
799
|
+
callback
|
|
800
|
+
);
|
|
801
|
+
}
|
|
802
|
+
|
|
803
|
+
static onAuthorization(callback: Function): Subscription {
|
|
804
|
+
return BackgroundGeolocation.addListener(Events.AUTHORIZATION, callback);
|
|
805
|
+
}
|
|
806
|
+
|
|
807
|
+
/**
|
|
808
|
+
* iOS only. Fires when a background location push (apns-push-type: background)
|
|
809
|
+
* wakes the live app. The event carries `{ requestId, locationQueryId }`.
|
|
810
|
+
* Your handler should obtain a location and deliver it (e.g. via socket), then
|
|
811
|
+
* call `BackgroundGeolocation.finishLocationPush(requestId)` so iOS can release
|
|
812
|
+
* the app — within ~25s, or iOS ends it for you.
|
|
813
|
+
*
|
|
814
|
+
* Kill-state pushes (apns-push-type: location) are handled natively by the
|
|
815
|
+
* Location Push Service Extension instead and never reach JS.
|
|
816
|
+
*/
|
|
817
|
+
static onLocationPush(callback: Function): Subscription {
|
|
818
|
+
return BackgroundGeolocation.addListener(Events.LOCATIONPUSH, callback);
|
|
819
|
+
}
|
|
820
|
+
|
|
821
|
+
/**
|
|
822
|
+
* iOS only. Tell the native layer that JS finished handling the background
|
|
823
|
+
* location push identified by `requestId` (from the onLocationPush event).
|
|
824
|
+
* No-op on Android.
|
|
825
|
+
*/
|
|
826
|
+
static finishLocationPush(requestId: string): Promise<void> {
|
|
827
|
+
if (Platform.OS !== 'ios') {
|
|
828
|
+
return Promise.resolve();
|
|
829
|
+
}
|
|
830
|
+
return new Promise((resolve, reject) =>
|
|
831
|
+
NativeBgGeolocation.finishLocationPush(requestId, resolve, reject)
|
|
832
|
+
);
|
|
833
|
+
}
|
|
834
|
+
|
|
835
|
+
// ─── Logging / Debug ──────────────────────────────────────────────────────
|
|
836
|
+
static setLogLevel(value: number): Promise<any> {
|
|
837
|
+
return new Promise((resolve, reject) =>
|
|
838
|
+
NativeBgGeolocation.setConfig({ logLevel: value }, resolve, reject)
|
|
839
|
+
);
|
|
840
|
+
}
|
|
841
|
+
|
|
842
|
+
static getLog(): Promise<string> {
|
|
843
|
+
return logger.getLog();
|
|
844
|
+
}
|
|
845
|
+
|
|
846
|
+
static destroyLog(): Promise<void> {
|
|
847
|
+
return logger.destroyLog();
|
|
848
|
+
}
|
|
849
|
+
|
|
850
|
+
static emailLog(email: string): Promise<void> {
|
|
851
|
+
return logger.emailLog(email);
|
|
852
|
+
}
|
|
853
|
+
|
|
854
|
+
// ─── Utility ──────────────────────────────────────────────────────────────
|
|
855
|
+
static isPowerSaveMode(): Promise<boolean> {
|
|
856
|
+
return new Promise((resolve, reject) =>
|
|
857
|
+
NativeBgGeolocation.isPowerSaveMode(resolve, reject)
|
|
858
|
+
);
|
|
859
|
+
}
|
|
860
|
+
|
|
861
|
+
static getSensors(): Promise<any> {
|
|
862
|
+
return new Promise((resolve, reject) =>
|
|
863
|
+
NativeBgGeolocation.getSensors(resolve, reject)
|
|
864
|
+
);
|
|
865
|
+
}
|
|
866
|
+
|
|
867
|
+
static getDeviceInfo(): Promise<any> {
|
|
868
|
+
return new Promise((resolve, reject) =>
|
|
869
|
+
NativeBgGeolocation.getDeviceInfo(resolve, reject)
|
|
870
|
+
);
|
|
871
|
+
}
|
|
872
|
+
|
|
873
|
+
/**
|
|
874
|
+
* iOS only. Resolves the device's location-push APNs token (hex string), or
|
|
875
|
+
* `null` if not yet available / unsupported. Ship this token to your server
|
|
876
|
+
* so it can send APNs location pushes that wake the Location Push Service
|
|
877
|
+
* Extension and fetch a location even when the app is force-quit.
|
|
878
|
+
*
|
|
879
|
+
* Android resolves `null`.
|
|
880
|
+
*/
|
|
881
|
+
static getLocationPushToken(): Promise<string | null> {
|
|
882
|
+
if (Platform.OS !== 'ios') {
|
|
883
|
+
return Promise.resolve(null);
|
|
884
|
+
}
|
|
885
|
+
return new Promise((resolve, reject) =>
|
|
886
|
+
NativeBgGeolocation.getLocationPushToken(resolve, reject)
|
|
887
|
+
);
|
|
888
|
+
}
|
|
889
|
+
|
|
890
|
+
/**
|
|
891
|
+
* iOS only. Resolves the device's standard APNs token (hex), or `null`. Ship
|
|
892
|
+
* this to your server so it can send background pushes (apns-push-type:
|
|
893
|
+
* background, content-available:1) that wake the live app for the hybrid
|
|
894
|
+
* native→JS→socket path. Android resolves `null`.
|
|
895
|
+
*/
|
|
896
|
+
static getApnsDeviceToken(): Promise<string | null> {
|
|
897
|
+
if (Platform.OS !== 'ios') {
|
|
898
|
+
return Promise.resolve(null);
|
|
899
|
+
}
|
|
900
|
+
return new Promise((resolve, reject) =>
|
|
901
|
+
NativeBgGeolocation.getApnsDeviceToken(resolve, reject)
|
|
902
|
+
);
|
|
903
|
+
}
|
|
904
|
+
|
|
905
|
+
/**
|
|
906
|
+
* iOS only. Provide the Location Push Service Extension with its delivery
|
|
907
|
+
* config so it can report a location when woken by an APNs location push —
|
|
908
|
+
* even when the app is force-quit. The extension tries the socket channel
|
|
909
|
+
* first, then falls back to REST.
|
|
910
|
+
*
|
|
911
|
+
* @param config
|
|
912
|
+
* socketUrl?: string base URL, e.g. https://host
|
|
913
|
+
* socketPath?: string socket.io path, e.g. /socket/location
|
|
914
|
+
* socketEvent?: string emit event name, e.g. location:update
|
|
915
|
+
* socketAuthToken?: string bearer/JWT sent in the socket CONNECT auth
|
|
916
|
+
* socketTimeout?: number seconds before falling back to REST (default 8)
|
|
917
|
+
* url?: string REST fallback endpoint (defaults to http.url)
|
|
918
|
+
* accessToken?: string bearer for the REST fallback
|
|
919
|
+
* extras?: object merged into the uploaded location's `extras`
|
|
920
|
+
*
|
|
921
|
+
* No-op on Android.
|
|
922
|
+
*/
|
|
923
|
+
static setLocationPushConfig(config: Record<string, any>): Promise<void> {
|
|
924
|
+
if (Platform.OS !== 'ios') {
|
|
925
|
+
return Promise.resolve();
|
|
926
|
+
}
|
|
927
|
+
return new Promise((resolve, reject) =>
|
|
928
|
+
NativeBgGeolocation.setLocationPushConfig(config, resolve, reject)
|
|
929
|
+
);
|
|
930
|
+
}
|
|
931
|
+
|
|
932
|
+
static playSound(soundId: number): void {
|
|
933
|
+
NativeBgGeolocation.playSound(soundId);
|
|
934
|
+
}
|
|
935
|
+
}
|