@doorstepai/dropoff-sdk 2.2.0 → 2.2.2
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 +267 -112
- package/android/build.gradle +5 -1
- package/android/src/main/java/com/doorstepai/dropoffsdk/DoorstepAIModule.kt +368 -136
- package/ios/DoorstepAI.mm +8 -1
- package/ios/DoorstepAI.swift +120 -139
- package/ios/DoorstepDropoffSDK.xcframework/Info.plist +5 -5
- package/ios/DoorstepDropoffSDK.xcframework/ios-arm64/DoorstepDropoffSDK.framework/DoorstepDropoffSDK +0 -0
- package/ios/DoorstepDropoffSDK.xcframework/ios-arm64/DoorstepDropoffSDK.framework/Modules/DoorstepDropoffSDK.swiftmodule/arm64-apple-ios.abi.json +10066 -6190
- package/ios/DoorstepDropoffSDK.xcframework/ios-arm64/DoorstepDropoffSDK.framework/Modules/DoorstepDropoffSDK.swiftmodule/arm64-apple-ios.private.swiftinterface +82 -0
- package/ios/DoorstepDropoffSDK.xcframework/ios-arm64/DoorstepDropoffSDK.framework/Modules/DoorstepDropoffSDK.swiftmodule/arm64-apple-ios.swiftdoc +0 -0
- package/ios/DoorstepDropoffSDK.xcframework/ios-arm64/DoorstepDropoffSDK.framework/Modules/DoorstepDropoffSDK.swiftmodule/arm64-apple-ios.swiftinterface +82 -0
- package/ios/DoorstepDropoffSDK.xcframework/ios-arm64/DoorstepDropoffSDK.framework/_CodeSignature/CodeResources +10 -10
- package/ios/DoorstepDropoffSDK.xcframework/ios-arm64/dSYMs/DoorstepDropoffSDK.framework.dSYM/Contents/Resources/DWARF/DoorstepDropoffSDK +0 -0
- package/ios/DoorstepDropoffSDK.xcframework/ios-arm64/dSYMs/DoorstepDropoffSDK.framework.dSYM/Contents/Resources/Relocations/aarch64/DoorstepDropoffSDK.yml +3833 -3248
- package/ios/DoorstepDropoffSDK.xcframework/ios-arm64_x86_64-simulator/DoorstepDropoffSDK.framework/DoorstepDropoffSDK +0 -0
- package/ios/DoorstepDropoffSDK.xcframework/ios-arm64_x86_64-simulator/DoorstepDropoffSDK.framework/Modules/DoorstepDropoffSDK.swiftmodule/arm64-apple-ios-simulator.abi.json +10066 -6190
- package/ios/DoorstepDropoffSDK.xcframework/ios-arm64_x86_64-simulator/DoorstepDropoffSDK.framework/Modules/DoorstepDropoffSDK.swiftmodule/arm64-apple-ios-simulator.private.swiftinterface +82 -0
- package/ios/DoorstepDropoffSDK.xcframework/ios-arm64_x86_64-simulator/DoorstepDropoffSDK.framework/Modules/DoorstepDropoffSDK.swiftmodule/arm64-apple-ios-simulator.swiftdoc +0 -0
- package/ios/DoorstepDropoffSDK.xcframework/ios-arm64_x86_64-simulator/DoorstepDropoffSDK.framework/Modules/DoorstepDropoffSDK.swiftmodule/arm64-apple-ios-simulator.swiftinterface +82 -0
- package/ios/DoorstepDropoffSDK.xcframework/ios-arm64_x86_64-simulator/DoorstepDropoffSDK.framework/Modules/DoorstepDropoffSDK.swiftmodule/x86_64-apple-ios-simulator.abi.json +10066 -6190
- package/ios/DoorstepDropoffSDK.xcframework/ios-arm64_x86_64-simulator/DoorstepDropoffSDK.framework/Modules/DoorstepDropoffSDK.swiftmodule/x86_64-apple-ios-simulator.private.swiftinterface +82 -0
- package/ios/DoorstepDropoffSDK.xcframework/ios-arm64_x86_64-simulator/DoorstepDropoffSDK.framework/Modules/DoorstepDropoffSDK.swiftmodule/x86_64-apple-ios-simulator.swiftdoc +0 -0
- package/ios/DoorstepDropoffSDK.xcframework/ios-arm64_x86_64-simulator/DoorstepDropoffSDK.framework/Modules/DoorstepDropoffSDK.swiftmodule/x86_64-apple-ios-simulator.swiftinterface +82 -0
- package/ios/DoorstepDropoffSDK.xcframework/ios-arm64_x86_64-simulator/DoorstepDropoffSDK.framework/_CodeSignature/CodeResources +20 -20
- package/ios/DoorstepDropoffSDK.xcframework/ios-arm64_x86_64-simulator/dSYMs/DoorstepDropoffSDK.framework.dSYM/Contents/Resources/DWARF/DoorstepDropoffSDK +0 -0
- package/ios/DoorstepDropoffSDK.xcframework/ios-arm64_x86_64-simulator/dSYMs/DoorstepDropoffSDK.framework.dSYM/Contents/Resources/Relocations/aarch64/DoorstepDropoffSDK.yml +3833 -3248
- package/ios/DoorstepDropoffSDK.xcframework/ios-arm64_x86_64-simulator/dSYMs/DoorstepDropoffSDK.framework.dSYM/Contents/Resources/Relocations/x86_64/DoorstepDropoffSDK.yml +3802 -3233
- package/lib/module/DoorstepAI.js +306 -71
- package/lib/module/DoorstepAI.js.map +1 -1
- package/lib/module/RootDoorstepAI.js +50 -32
- package/lib/module/RootDoorstepAI.js.map +1 -1
- package/lib/module/index.js.map +1 -1
- package/lib/typescript/src/DoorstepAI.d.ts +271 -73
- package/lib/typescript/src/DoorstepAI.d.ts.map +1 -1
- package/lib/typescript/src/RootDoorstepAI.d.ts +24 -7
- package/lib/typescript/src/RootDoorstepAI.d.ts.map +1 -1
- package/lib/typescript/src/index.d.ts +1 -1
- package/lib/typescript/src/index.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/DoorstepAI.tsx +425 -91
- package/src/RootDoorstepAI.tsx +75 -45
- package/src/index.tsx +6 -0
package/README.md
CHANGED
|
@@ -41,9 +41,28 @@ const App = () => {
|
|
|
41
41
|
}
|
|
42
42
|
```
|
|
43
43
|
|
|
44
|
-
This sets the API key
|
|
44
|
+
This sets the API key, initializes the SDK, and runs the permission sequence when
|
|
45
|
+
the app launches. Every part of it is available a la carte on `DoorstepAI` — the
|
|
46
|
+
component exists so a host that just wants the default flow does not have to write
|
|
47
|
+
it.
|
|
45
48
|
|
|
46
|
-
The notification title/text is
|
|
49
|
+
The notification title/text is passed to Android's foreground service, so you get
|
|
50
|
+
full control over that text.
|
|
51
|
+
|
|
52
|
+
Optional props:
|
|
53
|
+
|
|
54
|
+
| prop | default | what it does |
|
|
55
|
+
|---|---|---|
|
|
56
|
+
| `permissions` | *(every bucket)* | The whitelist handed to `requestPermissions`: **exactly these buckets are requested and nothing else.** See [Permissions](#-permissions). |
|
|
57
|
+
| `requestBackgroundLocation` | `true` | Run the second-phase `locationAlways` request once foreground location is granted. It has to be a second phase because Android auto-denies a background ask bundled with the foreground one. Turn it off if your own onboarding asks for "Allow all the time". |
|
|
58
|
+
| `requestBluetooth` | `true` | **Deprecated** — use `permissions`, which can narrow any bucket rather than just this one. `false` drops the platform's Bluetooth bucket from the default whitelist. |
|
|
59
|
+
|
|
60
|
+
```jsx
|
|
61
|
+
<RootDoorstepAI
|
|
62
|
+
apiKey="YOUR_API_KEY_HERE"
|
|
63
|
+
permissions={['location', 'motion']} // no Bluetooth, no notifications
|
|
64
|
+
/>
|
|
65
|
+
```
|
|
47
66
|
|
|
48
67
|
---
|
|
49
68
|
|
|
@@ -93,62 +112,118 @@ import { DoorstepAI } from "@doorstepai/dropoff-sdk"
|
|
|
93
112
|
|
|
94
113
|
## 🔧 SDK API
|
|
95
114
|
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
NOTE: You should never need to call this method directly.
|
|
101
|
-
|
|
102
|
-
---
|
|
103
|
-
|
|
104
|
-
### `DoorstepAI.setApiKey(apiKey: string): void`
|
|
105
|
-
|
|
106
|
-
Sets the API key to authenticate SDK usage.
|
|
107
|
-
|
|
108
|
-
---
|
|
109
|
-
|
|
110
|
-
### `DoorstepAI.startDeliveryByPlaceID(placeID: string, deliveryId: string): Promise<string>`
|
|
111
|
-
|
|
112
|
-
Starts a delivery using a Google Place ID. Returns a session ID on success.
|
|
115
|
+
Every method below is a thin pass-through to the native iOS/Android SDK. Where a
|
|
116
|
+
method exists on only one platform it says so, and it **rejects** on the other
|
|
117
|
+
rather than resolving a fabricated value — a helper that quietly resolved
|
|
118
|
+
`true`/`[]` would read as "granted" / "nothing needed" to a cross-platform host.
|
|
113
119
|
|
|
114
|
-
|
|
120
|
+
### Setup
|
|
115
121
|
|
|
116
|
-
|
|
122
|
+
| method | notes |
|
|
123
|
+
|---|---|
|
|
124
|
+
| `init(notificationTitle?, notificationText?): Promise<void>` | Android only (no-op on iOS). Handled for you by `<RootDoorstepAI />`. The title/text go on the foreground-service notification. |
|
|
125
|
+
| `setApiKey(apiKey): void` | Collection API key. |
|
|
126
|
+
| `setDoorstepGoApiKey(apiKey): void` | Doorstep Go is a **separate credential and realm**; a no-op if you do not use it. |
|
|
127
|
+
| `configureRemoteLogging({ enabled, minLevel?, flushIntervalSeconds?, batchSize?, maxQueueSize? }): void` | iOS only (no-op on Android, which drives remote logging from remote config). |
|
|
128
|
+
| `debugStateJson(): Promise<string>` | iOS only. Free-form internal-state dump for bug reports — never branch on it. |
|
|
129
|
+
| `retryGnssCallbacks(): Promise<boolean>` | Android only. Re-registers raw-GNSS callbacks after the OS silently stops delivering them. |
|
|
130
|
+
| `enableDevMode(apiKey)` / `validateDevModeAccess()` / `disableDevMode()` | Dev tooling. The last two are Android-only and answer `false` on iOS. |
|
|
117
131
|
|
|
118
|
-
|
|
132
|
+
### Deliveries
|
|
119
133
|
|
|
120
|
-
|
|
134
|
+
All four starters take the same trailing `StartDeliveryOptions`:
|
|
121
135
|
|
|
122
|
-
|
|
136
|
+
```ts
|
|
137
|
+
type StartDeliveryOptions = {
|
|
138
|
+
timeoutSeconds?: number; // hard session cap; OMIT for none
|
|
139
|
+
autoStopAfterDropoffSeconds?: number; // countdown once markDropoff is called
|
|
140
|
+
manualForeground?: boolean; // Android only: host owns the FGS
|
|
141
|
+
customerId?: string;
|
|
142
|
+
driverId?: string;
|
|
143
|
+
};
|
|
144
|
+
```
|
|
123
145
|
|
|
124
|
-
|
|
146
|
+
| method | notes |
|
|
147
|
+
|---|---|
|
|
148
|
+
| `startDeliveryByAddressString(address, deliveryId, timeoutSeconds?, coordinates?, options?)` | Preferred. Pass `coordinates` when you have them. |
|
|
149
|
+
| `startDeliveryByAddress(address: AddressType, deliveryId, timeoutSeconds?, coordinates?, options?)` | Structured address. |
|
|
150
|
+
| `startDeliveryByPlaceID(placeID, deliveryId, timeoutSeconds?, options?)` | Google Place ID. |
|
|
151
|
+
| `startDeliveryByLatLng(lat, lng, subUnit, deliveryId, timeoutSeconds?, options?)` | **Deprecated** — use an address method with `coordinates`. |
|
|
152
|
+
| `startDeliveryByPlusCode(plusCode, deliveryId, timeoutSeconds?, options?)` | **Deprecated** — same. |
|
|
153
|
+
| `markDropoff(deliveryId, 'pod' \| 'non_pod'): Promise<void>` | Also arms `autoStopAfterDropoffSeconds` and gates the geofence-EXIT stop. |
|
|
154
|
+
| `stopDelivery(deliveryId): Promise<void>` | |
|
|
155
|
+
| `newEvent(eventName, deliveryId, timestamp?): Promise<...>` | `timestamp` is optional epoch **seconds**. |
|
|
125
156
|
|
|
126
157
|
```ts
|
|
127
158
|
type AddressType = {
|
|
128
159
|
streetNumber: string;
|
|
129
160
|
route: string;
|
|
130
|
-
subPremise: string;
|
|
131
|
-
locality: string;
|
|
132
|
-
administrativeAreaLevel1: string;
|
|
161
|
+
subPremise: string; // apartment, suite, unit
|
|
162
|
+
locality: string; // city
|
|
163
|
+
administrativeAreaLevel1: string; // state/province
|
|
133
164
|
postalCode: string;
|
|
134
|
-
}
|
|
165
|
+
};
|
|
135
166
|
```
|
|
136
167
|
|
|
137
|
-
|
|
168
|
+
**`timeoutSeconds` omitted means NO backstop**, which is the native behaviour on
|
|
169
|
+
both platforms. (An older version of this wrapper substituted 3600 s here and
|
|
170
|
+
force-stopped every delivery at one hour.)
|
|
138
171
|
|
|
139
|
-
|
|
172
|
+
One cross-platform difference the wrapper does not paper over: **Android resolves
|
|
173
|
+
the server session id** (`{"id":"<uuid>"}`) from a starter and **iOS resolves
|
|
174
|
+
nothing** — native returns `Void` there. Treat a resolved promise as the success
|
|
175
|
+
signal, not a truthy return value. On iOS, listen for the SDK's
|
|
176
|
+
`sessionServerIdAssignedNotification` natively if you need the id.
|
|
140
177
|
|
|
141
|
-
|
|
178
|
+
### Route geofencing
|
|
142
179
|
|
|
143
|
-
|
|
180
|
+
The SDK fences each stop, auto-starts a session on geofence ENTER and stops it on
|
|
181
|
+
EXIT (EXIT is gated on `markDropoff`; otherwise the per-session `timeoutSeconds`
|
|
182
|
+
backstop cleans up). Needs location permission, and **background operation needs
|
|
183
|
+
`locationAlways`**.
|
|
144
184
|
|
|
145
|
-
|
|
185
|
+
```ts
|
|
186
|
+
type DeliveryStop = {
|
|
187
|
+
deliveryId: string;
|
|
188
|
+
address: string;
|
|
189
|
+
latitude: number;
|
|
190
|
+
longitude: number;
|
|
191
|
+
radiusMeters?: number; // default: options.defaultRadiusMeters (250)
|
|
192
|
+
customerId?: string;
|
|
193
|
+
driverId?: string;
|
|
194
|
+
};
|
|
195
|
+
|
|
196
|
+
type RouteGeofenceOptions = {
|
|
197
|
+
defaultRadiusMeters?: number; // 250
|
|
198
|
+
timeoutSeconds?: number; // per auto-started session
|
|
199
|
+
autoStopAfterDropoffSeconds?: number;
|
|
200
|
+
manualForeground?: boolean; // Android only; ignored on iOS
|
|
201
|
+
};
|
|
202
|
+
```
|
|
146
203
|
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
204
|
+
| method | notes |
|
|
205
|
+
|---|---|
|
|
206
|
+
| `startRouteGeofencing(stops, options?): Promise<void>` | Rejects if no stop has a `deliveryId` + coordinates. |
|
|
207
|
+
| `updateRouteStops(stops): Promise<void>` | Replaces the list in place. **Removing a stop that has an active session stops it immediately** (reason `removed_from_route`) — not EXIT-driven, not dropoff-gated. Does not extend the route lease. |
|
|
208
|
+
| `stopRouteGeofencing(): Promise<void>` | Teardown is handed to the tracking service / region manager, so `getMonitoredStops()` can still show the old list for a moment. |
|
|
209
|
+
| `resumeRouteGeofencingIfNeeded(): Promise<void>` | **Call this on every launch.** A per-launch host obligation: without it Android silently loses route monitoring across a process kill. |
|
|
210
|
+
| `getMonitoredStops(): Promise<DeliveryStop[]>` | The SDK's *intent* registry, not the OS's registered-region set. |
|
|
211
|
+
| `addGeofenceSessionListener(cb): EmitterSubscription \| undefined` | `{ deliveryId, type: 'STARTED' \| 'STOPPED', reason }`. Call `.remove()` to unsubscribe. |
|
|
150
212
|
|
|
151
|
-
|
|
213
|
+
```ts
|
|
214
|
+
const sub = DoorstepAI.addGeofenceSessionListener(({ deliveryId, type, reason }) => {
|
|
215
|
+
console.log(type, deliveryId, reason);
|
|
216
|
+
});
|
|
217
|
+
await DoorstepAI.startRouteGeofencing(stops, { defaultRadiusMeters: 250 });
|
|
218
|
+
// ...later
|
|
219
|
+
sub?.remove();
|
|
220
|
+
```
|
|
221
|
+
|
|
222
|
+
### Permissions
|
|
223
|
+
|
|
224
|
+
`checkPermissions`, `checkPermissionsJson`, `requestPermissions`,
|
|
225
|
+
`allPermissionBuckets`, `notePermissionRequestResult`, and the Android-only query
|
|
226
|
+
helpers. See [Permissions](#-permissions) below — that section is the reference.
|
|
152
227
|
|
|
153
228
|
---
|
|
154
229
|
|
|
@@ -234,105 +309,185 @@ your own `AndroidManifest.xml`:
|
|
|
234
309
|
|
|
235
310
|
`<RootDoorstepAI />` does this for you. Use the API directly if you drive
|
|
236
311
|
permissions from your own onboarding flow — every method delegates to the native
|
|
237
|
-
SDK, so the
|
|
312
|
+
SDK's own whitelist permission API, so the buckets, the states, the prompt order
|
|
313
|
+
and the "what will I decline to ask, and why" planning stay whatever the SDK says
|
|
314
|
+
they are.
|
|
238
315
|
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
`DoorstepAI.requestAllPermissions(requestAlwaysLocation:requestBluetooth:onlyIfNotDetermined:)`
|
|
245
|
-
on iOS.
|
|
316
|
+
**One requester, both platforms. No argument requests everything; an argument is a
|
|
317
|
+
whitelist and nothing outside it is ever asked for.** Do not branch on
|
|
318
|
+
`Platform.OS` to ask for permissions — the branch is inside the wrapper, on
|
|
319
|
+
`DoorstepAI.requestPermissions(_ permissions:…)` (iOS) and
|
|
320
|
+
`DoorstepAI.requestPermissions(activity, permissions)` (Android).
|
|
246
321
|
|
|
247
322
|
```ts
|
|
248
|
-
|
|
249
|
-
|
|
323
|
+
await DoorstepAI.requestPermissions(); // every bucket
|
|
324
|
+
await DoorstepAI.requestPermissions(['locationWhenInUse']); // only this one
|
|
325
|
+
await DoorstepAI.requestPermissions({ // object form
|
|
326
|
+
permissions: ['location', 'motion'],
|
|
327
|
+
onlyIfNotDetermined: true, // iOS
|
|
328
|
+
timeoutSeconds: 60,
|
|
329
|
+
});
|
|
330
|
+
```
|
|
250
331
|
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
332
|
+
#### Buckets
|
|
333
|
+
|
|
334
|
+
A **bucket** is one user-visible OS decision. They are deliberately OS-specific,
|
|
335
|
+
because the platforms are — only the two location buckets exist on both:
|
|
336
|
+
|
|
337
|
+
| bucket | iOS | Android |
|
|
338
|
+
|---|---|---|
|
|
339
|
+
| `locationWhenInUse` | `requestWhenInUseAuthorization` | `ACCESS_FINE_LOCATION` + `ACCESS_COARSE_LOCATION` |
|
|
340
|
+
| `locationAlways` | `requestAlwaysAuthorization` | `ACCESS_BACKGROUND_LOCATION` |
|
|
341
|
+
| `motionFitness` | Motion & Fitness | — |
|
|
342
|
+
| `activityRecognition` | — | `ACTIVITY_RECOGNITION` |
|
|
343
|
+
| `bluetooth` | `CBCentralManager` | — |
|
|
344
|
+
| `bluetoothScan` | — | `BLUETOOTH_SCAN` (API 31+) |
|
|
345
|
+
| `nearbyWifiDevices` | — | `NEARBY_WIFI_DEVICES` (API 33+) |
|
|
346
|
+
| `notifications` | — | `POST_NOTIFICATIONS` (API 33+) |
|
|
347
|
+
|
|
348
|
+
You can pass **either platform's** name on either platform: the wrapper translates
|
|
349
|
+
the counterpart (`motionFitness` ⇄ `activityRecognition`, `bluetooth` ⇄
|
|
350
|
+
`bluetoothScan`), so one whitelist works on both without a `Platform.OS` branch. A
|
|
351
|
+
name with no counterpart at all (`notifications` on iOS) comes back in
|
|
352
|
+
`unsupported` rather than being dropped in silence. The coarse aliases `'location'`
|
|
353
|
+
(→ both location buckets), `'motion'` / `'activity'` and `'bluetooth'` are still
|
|
354
|
+
accepted — they are what the published 2.x API took.
|
|
355
|
+
|
|
356
|
+
`DoorstepAI.allPermissionBuckets()` returns this platform's list if you want to
|
|
357
|
+
build a permission screen without hardcoding it.
|
|
358
|
+
|
|
359
|
+
#### States
|
|
360
|
+
|
|
361
|
+
Eight states, **the same names on both platforms**, so host code branches once:
|
|
362
|
+
|
|
363
|
+
| state | meaning |
|
|
364
|
+
|---|---|
|
|
365
|
+
| `granted` | held right now |
|
|
366
|
+
| `notDetermined` | never asked; a request will show a dialog |
|
|
367
|
+
| `whenInUseOnly` | **foreground location held, background not.** Only ever reported for `locationAlways` |
|
|
368
|
+
| `denied` | refused, another prompt is still possible (Android only) |
|
|
369
|
+
| `permanentlyDenied` | refused, no further prompt possible — deep-link to Settings. Every iOS refusal lands here |
|
|
370
|
+
| `restricted` | blocked by device policy / MDM / Screen Time |
|
|
371
|
+
| `unavailable` | the OS version or the hardware does not have it. Not a failure |
|
|
372
|
+
| `notDeclared` | **your build is missing the declaration** (`<uses-permission>` / `NS…UsageDescription`). Not a user refusal — fixable by you |
|
|
373
|
+
|
|
374
|
+
`whenInUseOnly` is the load-bearing one: **never treat it as `granted`.** Background
|
|
375
|
+
collection and route geofencing do not work in it.
|
|
254
376
|
|
|
255
|
-
|
|
256
|
-
|
|
377
|
+
```ts
|
|
378
|
+
// Read the current state. Pure observation — never shows a dialog.
|
|
379
|
+
const { statuses } = await DoorstepAI.checkPermissions();
|
|
380
|
+
if (statuses.locationAlways?.state === 'whenInUseOnly') {
|
|
381
|
+
// foreground-only: no background collection, no route geofencing
|
|
382
|
+
}
|
|
383
|
+
if (statuses.locationWhenInUse?.state === 'permanentlyDenied') {
|
|
384
|
+
// a request would be answered instantly with no dialog — send them to Settings
|
|
257
385
|
}
|
|
258
|
-
|
|
259
|
-
checkPermissions(): Promise<PermissionStatus>;
|
|
260
|
-
requestPermissions(options?: PermissionRequestOptions): Promise<PermissionStatus>;
|
|
261
386
|
```
|
|
262
387
|
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
388
|
+
#### What a request answers with
|
|
389
|
+
|
|
390
|
+
`requestPermissions` **resolves only after the user has answered**, with the settled
|
|
391
|
+
state — a status read while a prompt is still up would be a lie. Everything native
|
|
392
|
+
declined to ask comes back explained rather than silently not happening:
|
|
267
393
|
|
|
268
|
-
|
|
269
|
-
const
|
|
270
|
-
|
|
394
|
+
```ts
|
|
395
|
+
const result = await DoorstepAI.requestPermissions();
|
|
396
|
+
result.requested; // buckets a dialog was actually raised for
|
|
397
|
+
result.alreadyDetermined; // already answered, so left alone
|
|
398
|
+
result.unavailable; // absent on this device / missing from this build
|
|
399
|
+
result.deferred; // deliberately skipped, with the reason
|
|
400
|
+
result.statuses; // state of every whitelisted bucket, after settling
|
|
401
|
+
result.permissions; // legacy { location, motion, bluetooth } view
|
|
402
|
+
result.unsupported; // whitelist entries this platform has no bucket for
|
|
271
403
|
```
|
|
272
404
|
|
|
273
|
-
`
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
no permission list of its own. A bucket the native SDK needs no runtime grant for
|
|
278
|
-
on this OS version reports `granted` — `motion` on Android (sensor collection needs
|
|
279
|
-
none) and `bluetooth` below Android 12.
|
|
405
|
+
**Expect `locationAlways` in `deferred` on a full-whitelist call.** It is only ever
|
|
406
|
+
asked *alone* and only *after* foreground location is granted — Android auto-denies
|
|
407
|
+
a bundled background ask, and iOS shows the When-In-Use prompt first and offers the
|
|
408
|
+
Always upgrade later on its own schedule. So the standard two-phase flow is:
|
|
280
409
|
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
410
|
+
```ts
|
|
411
|
+
const first = await DoorstepAI.requestPermissions();
|
|
412
|
+
if (first.statuses.locationWhenInUse?.state === 'granted') {
|
|
413
|
+
await DoorstepAI.requestPermissions(['locationAlways']);
|
|
414
|
+
}
|
|
415
|
+
```
|
|
287
416
|
|
|
288
|
-
|
|
417
|
+
Device-measured, Moto G stylus 5G / Android 14: a full-whitelist call raises the
|
|
418
|
+
five askable dialogs in one batch and returns
|
|
419
|
+
`deferred: { locationAlways: 'ACCESS_BACKGROUND_LOCATION cannot be requested before
|
|
420
|
+
foreground location is granted…' }`. iPhone 16 Pro / iOS 26.6: it raises
|
|
421
|
+
`locationAlways`, `motionFitness` and `bluetooth` one at a time and returns
|
|
422
|
+
`deferred: { locationWhenInUse: 'covered by the locationAlways prompt in this call…' }`.
|
|
423
|
+
|
|
424
|
+
A second call made while one is still in flight does not interleave prompt
|
|
425
|
+
sequences: iOS reports every bucket as `deferred`, Android rejects with
|
|
426
|
+
`E_PERMISSION_REQUEST_IN_FLIGHT`. If the user never answers, the wait gives up after
|
|
427
|
+
`timeoutSeconds` (default 120 s) and resolves with the state as it stands.
|
|
428
|
+
|
|
429
|
+
iOS guidance from the SDK: call it **once, from a user-initiated flow**, not from
|
|
430
|
+
app launch.
|
|
431
|
+
|
|
432
|
+
#### Android: forward your grant results (optional, worth doing)
|
|
433
|
+
|
|
434
|
+
Android reports *identical* signals for "permanently denied" and "never asked", and
|
|
435
|
+
a **cancelled** dialog leaves the same trace as a denial. The SDK refuses to guess,
|
|
436
|
+
so without a real answer a refusal reports as the re-askable `denied`. Forward the
|
|
437
|
+
result and you get `permanentlyDenied` — and the JS promise settles on the answer
|
|
438
|
+
itself instead of on a window-focus heuristic:
|
|
439
|
+
|
|
440
|
+
```kotlin
|
|
441
|
+
// MainActivity.kt
|
|
442
|
+
import com.doorstepai.dropoffsdk.DoorstepAIModule
|
|
443
|
+
|
|
444
|
+
override fun onRequestPermissionsResult(
|
|
445
|
+
requestCode: Int, permissions: Array<out String>, grantResults: IntArray
|
|
446
|
+
) {
|
|
447
|
+
super.onRequestPermissionsResult(requestCode, permissions, grantResults)
|
|
448
|
+
DoorstepAIModule.notePermissionRequestResult(this, permissions, grantResults)
|
|
449
|
+
}
|
|
450
|
+
```
|
|
289
451
|
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
as:
|
|
452
|
+
There is a JS entry point too (`DoorstepAI.notePermissionRequestResult(permissions,
|
|
453
|
+
grantResults)`) if the values reach you there instead.
|
|
293
454
|
|
|
294
|
-
|
|
295
|
-
includeBluetooth = permissions === undefined || permissions.includes('bluetooth')
|
|
296
|
-
```
|
|
455
|
+
#### Legacy three-value view
|
|
297
456
|
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
457
|
+
`statuses` is the real answer, but every result also carries the
|
|
458
|
+
`{ location, motion, bluetooth }` × `granted | denied | prompt` map the published
|
|
459
|
+
2.x API returned, so existing hosts keep working. It is collapsed from `statuses`:
|
|
460
|
+
`whenInUseOnly` and `unavailable` → `granted`, `notDetermined` → `prompt`,
|
|
461
|
+
everything else (including `notDeclared`) → `denied`.
|
|
302
462
|
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
normalised to `'motion'` before it reaches native and is never a key of
|
|
306
|
-
`PermissionStatus`.
|
|
463
|
+
Two things it cannot tell you, which is why it is deprecated: While-In-Use vs
|
|
464
|
+
Always, and a host-build mistake vs a user refusal.
|
|
307
465
|
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
466
|
+
`motion` stays unconditionally `granted` on Android, exactly as in 2.x. That is the
|
|
467
|
+
honest answer to what the key asks — Android's IMU streams (accel, gyro, mag,
|
|
468
|
+
rotation vectors, barometer) need **no** runtime grant, so motion collection is
|
|
469
|
+
always possible there. `activityRecognition` adds only the step-counter streams,
|
|
470
|
+
and the SDK never blocks a session on it; read `statuses.activityRecognition` for
|
|
471
|
+
its real state. On iOS `motion` does track Motion & Fitness, which genuinely gates
|
|
472
|
+
`CMMotionActivityManager`, `CMSensorRecorder` and absolute altitude.
|
|
312
473
|
|
|
313
|
-
|
|
314
|
-
// Android only. On iOS the same intent is native's requestAlwaysLocation, which
|
|
315
|
-
// requestPermissions leaves at its default (true) — this method has no iOS
|
|
316
|
-
// counterpart and rejects there rather than inventing an answer.
|
|
317
|
-
if (Platform.OS === 'android') {
|
|
318
|
-
const { permissions } = await DoorstepAI.requestPermissions();
|
|
319
|
-
if (permissions.location === 'granted') {
|
|
320
|
-
if (!(await DoorstepAI.hasBackgroundLocationPermission())) {
|
|
321
|
-
await DoorstepAI.requestBackgroundLocationPermission();
|
|
322
|
-
}
|
|
323
|
-
}
|
|
324
|
-
}
|
|
325
|
-
```
|
|
474
|
+
#### Android-only query helpers
|
|
326
475
|
|
|
327
|
-
|
|
328
|
-
|
|
476
|
+
These reject on iOS rather than resolving `true`/`[]`, which a cross-platform host
|
|
477
|
+
would read as "granted" / "nothing needed".
|
|
329
478
|
|
|
330
479
|
```ts
|
|
331
|
-
await DoorstepAI.hasRequiredPermissions();
|
|
480
|
+
await DoorstepAI.hasRequiredPermissions(); // -> boolean
|
|
481
|
+
await DoorstepAI.hasBackgroundLocationPermission(); // -> boolean
|
|
482
|
+
await DoorstepAI.requestBackgroundLocationPermission();
|
|
332
483
|
|
|
333
|
-
// Want the grant results in JS? Request the SDK's own list with RN's API.
|
|
484
|
+
// Want the grant results in JS? Request the SDK's own flat list with RN's API.
|
|
334
485
|
const required = await DoorstepAI.getRequiredPermissions();
|
|
335
486
|
await PermissionsAndroid.requestMultiple(required);
|
|
336
487
|
```
|
|
337
488
|
|
|
489
|
+
`requestPermissions(['locationAlways'])` is the cross-platform way to express the
|
|
490
|
+
same intent as `requestBackgroundLocationPermission()`, and it reports back why if
|
|
491
|
+
the OS would have refused to show the prompt.
|
|
492
|
+
|
|
338
493
|
---
|
package/android/build.gradle
CHANGED
|
@@ -86,7 +86,11 @@ def kotlin_version = getExtOrDefault("kotlinVersion")
|
|
|
86
86
|
dependencies {
|
|
87
87
|
implementation "com.facebook.react:react-android"
|
|
88
88
|
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
|
|
89
|
-
implementation
|
|
89
|
+
// `api`, not `implementation`: the host Activity is expected to forward
|
|
90
|
+
// `onRequestPermissionsResult` to `DoorstepAI.notePermissionRequestResult(...)`
|
|
91
|
+
// (the only way the SDK can tell a re-askable denial from a permanent one), so
|
|
92
|
+
// the SDK's types have to be on the host's compile classpath.
|
|
93
|
+
api("ai.doorstep.com:doorstepai-dropoff-sdk:2.2.2")
|
|
90
94
|
api "org.jetbrains.kotlinx:kotlinx-serialization-json:1.5.1"
|
|
91
95
|
}
|
|
92
96
|
|