@pushpilotai/react-native 2.0.0 → 2.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/PushPilotReactNative.podspec +1 -1
- package/README.md +100 -5
- package/android/build.gradle +1 -1
- package/android/src/main/java/ai/pushpilot/reactnative/PushPilotModule.kt +43 -0
- package/ios/RNPushPilot.mm +53 -1
- package/ios/RNPushPilotBridge.swift +27 -3
- package/lib/module/NativePushPilot.js.map +1 -1
- package/lib/module/index.js +51 -2
- package/lib/module/index.js.map +1 -1
- package/lib/typescript/src/NativePushPilot.d.ts +5 -0
- package/lib/typescript/src/NativePushPilot.d.ts.map +1 -1
- package/lib/typescript/src/index.d.ts +27 -0
- package/lib/typescript/src/index.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/NativePushPilot.ts +13 -0
- package/src/index.tsx +71 -1
|
@@ -19,7 +19,7 @@ Pod::Spec.new do |s|
|
|
|
19
19
|
# To build against a local pushpilot-ios checkout instead, see README -> Local development.
|
|
20
20
|
spm_dependency(s,
|
|
21
21
|
url: "https://github.com/pushpilotai/pushpilot-ios.git",
|
|
22
|
-
requirement: { kind: "upToNextMajorVersion", minimumVersion: "2.
|
|
22
|
+
requirement: { kind: "upToNextMajorVersion", minimumVersion: "2.2.0" },
|
|
23
23
|
products: ["PushPilot"]
|
|
24
24
|
)
|
|
25
25
|
|
package/README.md
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
React Native wrapper for the PushPilot SDK. It registers your app's installation with PushPilot and passes in its push address: the Firebase Cloud Messaging (FCM) identifier on Android and the Apple (APNs) device token on iOS. You can then send pushes to individual users from the PushPilot dashboard. PushPilot pushes are shown and their taps recorded natively, with no JavaScript running.
|
|
4
4
|
|
|
5
|
-
- A thin layer over the native [Android SDK](https://github.com/pushpilotai/pushpilot-android) (`ai.pushpilot:sdk` 2.
|
|
5
|
+
- A thin layer over the native [Android SDK](https://github.com/pushpilotai/pushpilot-android) (`ai.pushpilot:sdk` 2.2.0) and [iOS SDK](https://github.com/pushpilotai/pushpilot-ios) (Swift package `PushPilot` 2.2.0). Every call goes straight to them; they do all syncing, retrying, storage, display and validation.
|
|
6
6
|
- No Firebase dependency. On Android your app keeps its own Firebase setup and passes the identifier in. iOS needs no Firebase at all: PushPilot sends to Apple directly.
|
|
7
7
|
- Never asks for notification permission. It reports whatever the user chose.
|
|
8
8
|
- Every call returns nothing and never throws into your app. Problems are logged.
|
|
@@ -146,6 +146,93 @@ Optional: set the notification icon and channel name with the Android SDK's meta
|
|
|
146
146
|
|
|
147
147
|
The [iOS SDK README](https://github.com/pushpilotai/pushpilot-ios#images-and-buttons-notification-service-extension) explains what the helper does and how it fails safely. The example's `NotificationService` target is set up this way.
|
|
148
148
|
|
|
149
|
+
## Live activities
|
|
150
|
+
|
|
151
|
+
From 2.1.1, PushPilot can start, update and end live activities by push, from the dashboard, a campaign or the server API: a score, a delivery or an upload that stays on screen and changes with each update. The native SDKs do all the work; your app starts none itself and needs no JavaScript beyond the two optional calls below.
|
|
152
|
+
|
|
153
|
+
### Android
|
|
154
|
+
|
|
155
|
+
Nothing to add: the Android SDK 2.1.1 draws each live activity as one ongoing notification on a "Live updates" channel, from the same receiver that shows your other PushPilot pushes. On Android 16 an activity sent as promoted shows as a Live Update (status chip, segmented progress) when the user allows it; the SDK's manifest merges the `POST_PROMOTED_NOTIFICATIONS` permission it needs, a normal permission granted at install. Taps open the activity's link like a push's, through `setLinkHandler` when one is set. See the [Android SDK README](https://github.com/pushpilotai/pushpilot-android#live-activities).
|
|
156
|
+
|
|
157
|
+
### iOS
|
|
158
|
+
|
|
159
|
+
Live activities started by push need iOS 17.2 or later; the app itself still runs on iOS 15.1. In Xcode (`ios/<App>.xcworkspace`):
|
|
160
|
+
|
|
161
|
+
1. **Add a Widget Extension:** **File › New › Target… › Widget Extension**, named for example `LiveActivity`, with the template's *Include …* options unticked. Keep its bundle id under the app's, set its deployment target to iOS 16.1 or later and its signing team to the app's; choose **Cancel** when Xcode asks to activate the new scheme. Delete the generated widget files except the bundle.
|
|
162
|
+
2. **Add the `PushPilotLive` library to the extension target only**, from the pushpilot-ios package: if the app's project already has it (for the Notification Service Extension), pick the extension under *General › Frameworks and Libraries › +*; otherwise **File › Add Package Dependencies…** with the pushpilot-ios repository URL. The app target needs nothing: the wrapper's pod already brings in `PushPilot`, which includes `PushPilotLive`. Like the Notification Service Extension, the Widget Extension uses no pods, so nothing goes in the `Podfile`.
|
|
163
|
+
3. **Make the bundle return PushPilot's widget**, which draws every PushPilot layout on the Lock Screen and in the Dynamic Island:
|
|
164
|
+
|
|
165
|
+
```swift
|
|
166
|
+
import PushPilotLive
|
|
167
|
+
import SwiftUI
|
|
168
|
+
import WidgetKit
|
|
169
|
+
|
|
170
|
+
@main
|
|
171
|
+
struct LiveActivityWidgets: WidgetBundle {
|
|
172
|
+
var body: some Widget {
|
|
173
|
+
PushPilotLiveActivityWidget(appGroup: "group.com.example.app")
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
```
|
|
177
|
+
|
|
178
|
+
To draw activities your own way, return an `ActivityConfiguration(for: PushPilotLiveAttributes.self)` instead; see the [iOS SDK README](https://github.com/pushpilotai/pushpilot-ios#live-activities).
|
|
179
|
+
4. **Add `NSSupportsLiveActivities`** (Boolean, `YES`) to the app's `Info.plist`. Without it iOS starts none, and the SDK tells PushPilot so.
|
|
180
|
+
5. **Optional: an App Group** for images in layouts. Add the *App Groups* capability with the same group to the app and the extension, pass it to the widget as above and to `init`:
|
|
181
|
+
|
|
182
|
+
```tsx
|
|
183
|
+
PushPilot.init('pp_sdk_...', { appGroup: 'group.com.example.app' });
|
|
184
|
+
```
|
|
185
|
+
|
|
186
|
+
The SDK then downloads the layout's https images into the group for the widget. Without one, image blocks show their fallback icon.
|
|
187
|
+
6. **Pass opened URLs to `handleLiveActivityURL`.** A tap on a live activity opens your app with the activity's link plus a `pushpilot_live` marker. `handleLiveActivityURL` counts the click once and resolves to your link without the marker, or `null` when the activity has none:
|
|
188
|
+
|
|
189
|
+
```tsx
|
|
190
|
+
import { Linking } from 'react-native';
|
|
191
|
+
|
|
192
|
+
const opened = async (url: string | null) => {
|
|
193
|
+
if (!url) return;
|
|
194
|
+
const link = await PushPilot.handleLiveActivityURL(url);
|
|
195
|
+
if (link) router.open(link); // null: the tap only opens the app
|
|
196
|
+
};
|
|
197
|
+
Linking.getInitialURL().then(opened);
|
|
198
|
+
Linking.addEventListener('url', ({ url }) => opened(url));
|
|
199
|
+
```
|
|
200
|
+
|
|
201
|
+
`Linking` needs `RCTLinkingManager` in your `AppDelegate` or `SceneDelegate`, as React Native's [Linking guide](https://reactnative.dev/docs/linking) describes. Other URLs come back unchanged, so you can pass every URL through it. On Android it resolves every URL unchanged.
|
|
202
|
+
|
|
203
|
+
The SDK watches PushPilot activities while the app runs and reports their tokens and state to PushPilot. An Expo app that regenerates its `ios/` folder can only add a Widget Extension with a config plugin, which PushPilot does not provide.
|
|
204
|
+
|
|
205
|
+
## In-app messages
|
|
206
|
+
|
|
207
|
+
From 2.2.0, messages you publish in the dashboard's in-app section show over your app: a modal, full screen, bottom sheet, banner, card, carousel, or a coach mark pointing at one of your views. The native SDKs fetch, cache and draw them (an HTML page in a transparent web view over the current screen) and report `shown`, `clicked` and `dismissed`. See the [Android](https://github.com/pushpilotai/pushpilot-android#in-app-messages) and [iOS](https://github.com/pushpilotai/pushpilot-ios#in-app-messages) READMEs for how messages are fetched, cached and locked down.
|
|
208
|
+
|
|
209
|
+
1. **Nothing to add for app-open messages.** With `init` called at startup, the first eligible message with the "app open" trigger shows when the app comes to the foreground. Messages are fetched after the installation's first sync, at most once a minute on foreground, and show only from what is already cached, never from the network.
|
|
210
|
+
2. **Named moments.** For a message whose trigger is an in-app call, call `showInApp` with its name where it should appear:
|
|
211
|
+
|
|
212
|
+
```tsx
|
|
213
|
+
const shown = await PushPilot.showInApp('checkout');
|
|
214
|
+
```
|
|
215
|
+
|
|
216
|
+
It resolves to `true` when a message is now on screen, and `false` when none is cached and eligible, another message is showing, it is past its cap or outside its dates, or the SDK has not started. It never rejects. The call runs on the native main thread for you.
|
|
217
|
+
3. **Coach marks.** A coach-mark message points at one of your views by the name its target uses in the dashboard. Pass the view's `ref` once it is mounted:
|
|
218
|
+
|
|
219
|
+
```tsx
|
|
220
|
+
const compose = useRef<ComponentRef<typeof View>>(null);
|
|
221
|
+
useEffect(() => {
|
|
222
|
+
PushPilot.markView(compose, 'compose');
|
|
223
|
+
return () => PushPilot.unmarkView('compose');
|
|
224
|
+
}, []);
|
|
225
|
+
|
|
226
|
+
<View ref={compose} collapsable={false}>
|
|
227
|
+
<Button title="Compose" onPress={openComposer} />
|
|
228
|
+
</View>
|
|
229
|
+
```
|
|
230
|
+
|
|
231
|
+
- Give a plain `<View>` `collapsable={false}`: React Native removes layout-only views from the native tree, and a view with no native counterpart cannot be marked. Native components (`Pressable`, `TextInput`, `Image`...) need nothing extra.
|
|
232
|
+
- `markView` also takes a view tag from `findNodeHandle`. A ref that is not mounted yet logs a warning and marks nothing; mark it again from an effect or `onLayout`.
|
|
233
|
+
- The native view is looked up on the UI thread (New Architecture). The SDK holds it weakly; a later view with the same name replaces it, and `unmarkView(name)` forgets it. A coach mark shows only while its view is on screen; otherwise it waits.
|
|
234
|
+
4. **Links.** A button's link closes the message and goes to `setLinkHandler`, the same handler tapped pushes use ([Taps](#taps-on-android-and-ios)). Without one, the system opens it.
|
|
235
|
+
|
|
149
236
|
## Integrate (Expo development build)
|
|
150
237
|
|
|
151
238
|
PushPilot has no Expo config plugin. What works without one:
|
|
@@ -212,6 +299,8 @@ The link handler and tap data come from the native SDKs' own APIs (`setLinkHandl
|
|
|
212
299
|
- **iOS no longer uses Firebase.** `setPushToken` on iOS now takes the APNs device token as hex. An FCM token or FID passed on iOS, the 1.x path, is ignored with a warning, so a 1.x app keeps the last token the SDK stored until you switch. Switch by adding the `AppDelegate` method above (or, on Expo, passing `getDevicePushTokenAsync`), and by giving PushPilot your APNs key.
|
|
213
300
|
- **Android pushes are shown for you.** If your 1.x app showed PushPilot pushes itself after `handleMessage` returned `true`, remove that code, or they appear twice.
|
|
214
301
|
- **New:** `setLinkHandler` and `setTapHandler`, on both platforms ([Taps](#taps-on-android-and-ios)).
|
|
302
|
+
- **2.1.1:** [live activities](#live-activities), with `init`'s `appGroup` and `handleLiveActivityURL`. Nothing changes for apps that do not use them.
|
|
303
|
+
- **2.2.0:** [in-app messages](#in-app-messages), with `showInApp`, `markView` and `unmarkView`. App-open messages show with no code; their links reach your existing `setLinkHandler`.
|
|
215
304
|
- Every other call is unchanged, including `init`'s `baseUrl`.
|
|
216
305
|
|
|
217
306
|
## API
|
|
@@ -226,7 +315,7 @@ import PushPilot, {
|
|
|
226
315
|
|
|
227
316
|
| Call | What it does |
|
|
228
317
|
|---|---|
|
|
229
|
-
| `init(sdkKey, { baseUrl? })` | Starts the SDK with your public SDK key. Call once at startup; later calls are ignored (including after a JavaScript reload). `baseUrl` defaults to `https://pushpilot.ai`; set it only for a self-hosted server. The native SDKs save the values, so a process started by a push or a tap before JavaScript runs can still send its events. |
|
|
318
|
+
| `init(sdkKey, { baseUrl?, appGroup? })` | Starts the SDK with your public SDK key. Call once at startup; later calls are ignored (including after a JavaScript reload). `baseUrl` defaults to `https://pushpilot.ai`; set it only for a self-hosted server. The native SDKs save the values, so a process started by a push or a tap before JavaScript runs can still send its events. `appGroup` (iOS) is the App Group shared with your Widget Extension, for images in [live activities](#live-activities); Android ignores it. |
|
|
230
319
|
| `setPushToken(token \| null)` | Stores the push identifier and syncs it. **Android:** the Firebase Installation ID from `register` / `onRegistered`, or the FCM token from `getToken` / `onTokenRefresh` where your Firebase library has no FID API; pass only one kind. **iOS:** the APNs device token as hex (`getDevicePushTokenAsync`, `getAPNSToken`), if you do not forward it from the `AppDelegate`; anything else is ignored with a warning. `null` clears it, and the device then stops receiving pushes. |
|
|
231
320
|
| `setExternalUserId(id \| null)` | Links this installation to your own user id (1 to 255 characters). One user can have many installations. `null` clears it, like `logout()`. |
|
|
232
321
|
| `setAttributes(record)` | Merges custom attributes. Values are strings, numbers or booleans; pass dates as RFC 3339 strings (`date.toISOString()`) and `null` to remove an attribute. Only attributes declared in the dashboard are stored. |
|
|
@@ -235,6 +324,10 @@ import PushPilot, {
|
|
|
235
324
|
| `forget()` | Deletes this installation from PushPilot and clears all local SDK state. A new installation is registered after your next PushPilot call or the next app launch. Use it in your account-deletion or privacy flow. |
|
|
236
325
|
| `handleMessage(data): boolean` | `true` when a received push's data has `source` equal to `pushpilot`. Answered in JavaScript with the native SDKs' rule; makes no native or network call. Use it to skip PushPilot pushes in your own message handlers. |
|
|
237
326
|
| `setLinkHandler(handler \| null)` | Receives the link (`string`) of each tapped PushPilot push instead of the system opening it, like the native SDKs' `setLinkHandler`. A new handler replaces the old one; `null` lets the system open links again. Set it before `init` to get the tap that launched the app. See [Taps](#taps-on-android-and-ios). |
|
|
327
|
+
| `handleLiveActivityURL(url): Promise<string \| null>` | For a URL your app was opened with: a tap on an iOS live activity is counted once and resolves to the activity's own link without PushPilot's marker, or `null` when it has none. Any other URL, and every URL on Android, resolves unchanged. Never rejects. See [Live activities](#live-activities). |
|
|
328
|
+
| `showInApp(name): Promise<boolean>` | Shows the first eligible cached [in-app message](#in-app-messages) whose trigger is `name`; resolves to whether one is now on screen. No network call. Never rejects. |
|
|
329
|
+
| `markView(ref \| viewTag, name)` | Names a mounted view (a `ref` or a `findNodeHandle` tag) for coach-mark messages whose target is `name`. A plain `<View>` needs `collapsable={false}`. A later view with the same name replaces it. |
|
|
330
|
+
| `unmarkView(name)` | Forgets the view marked with `name`. |
|
|
238
331
|
| `setTapHandler(handler \| null)` | Receives a `TappedNotification`, `{ notificationId: string, data: Record<string, string> }`, for each tapped PushPilot push that opens the app. `data` is the push's custom data, empty when it has none. A new handler replaces the old one; `null` stops it. Set it before `init` to get the tap that launched the app. |
|
|
239
332
|
|
|
240
333
|
Native, for the iOS `AppDelegate` (`import PushPilotReactNative`):
|
|
@@ -257,6 +350,8 @@ The data each sync carries, the `delivered` (Android) and `clicked` (both) event
|
|
|
257
350
|
- Initialises PushPilot at startup and sets a tap handler and a link handler before `init`. It shows the last tapped push's id and data, or its link.
|
|
258
351
|
- **Android:** forwards the Firebase Installation ID from `@react-native-firebase/messaging` (`register` and `onRegistered`, turned on in `example/firebase.json`), and has a permission button.
|
|
259
352
|
- **iOS:** no Firebase (`example/react-native.config.js` keeps React Native Firebase off iOS). The `AppDelegate` asks for permission at launch and forwards the device token, and the app has the Push Notifications entitlement and a `NotificationService` extension target.
|
|
353
|
+
- **Live activities:** `init` passes the App Group `group.pushpilot.reactnative.example`, and every URL the app is opened with goes through `handleLiveActivityURL`; the screen shows the link that comes back. On iOS the app has `NSSupportsLiveActivities`, the App Group, and a `LiveActivity` Widget Extension target (`example/ios/LiveActivity/`) that returns `PushPilotLiveActivityWidget` and links `PushPilotLive` from the pushpilot-ios package.
|
|
354
|
+
- **In-app messages:** a **Show in-app** button calls `showInApp('checkout')` and shows the result; the button is marked as the coach-mark target `example-button`.
|
|
260
355
|
- Buttons for set user id, set topics, logout and forget.
|
|
261
356
|
|
|
262
357
|
```bash
|
|
@@ -269,7 +364,7 @@ It builds and runs without any Firebase config; Android then has no push identif
|
|
|
269
364
|
|
|
270
365
|
- Put your SDK key in `PUSHPILOT_SDK_KEY` in `example/src/App.tsx`.
|
|
271
366
|
- Android: add your own `example/android/app/google-services.json`. It is git-ignored; never commit it. The build applies the Google Services plugin only when the file exists.
|
|
272
|
-
- iOS: set your signing team
|
|
367
|
+
- iOS: set your signing team, bundle ids and an App Group you own on all three targets, and give PushPilot the matching APNs key. The extensions' bundle ids must start with the app's.
|
|
273
368
|
|
|
274
369
|
On the iOS simulator you can try taps without a server:
|
|
275
370
|
|
|
@@ -294,7 +389,7 @@ and switch these three places locally (don't commit them):
|
|
|
294
389
|
|
|
295
390
|
1. **Android:** `cd ../pushpilot-android && ./gradlew :sdk:publishToMavenLocal`, then add `allprojects { repositories { mavenLocal { content { includeGroup("ai.pushpilot") } } } }` to `example/android/build.gradle` (or another app's root `build.gradle`).
|
|
296
391
|
2. **iOS:** in `PushPilotReactNative.podspec`, set the `spm_dependency` `url:` to the absolute path of your `pushpilot-ios` checkout. Local paths need React Native 0.84 or later; on 0.81 to 0.83 use `"file:///absolute/path/to/pushpilot-ios"` with `requirement: { kind: "branch", branch: "<branch>" }`, which builds the committed branch, not uncommitted edits.
|
|
297
|
-
3. **The example's Notification Service
|
|
392
|
+
3. **The example's extensions** (Notification Service and Live Activity, which share one package reference): in Xcode, replace the `pushpilot-ios` package under *Package Dependencies* with *Add Local…* and the checkout.
|
|
298
393
|
|
|
299
394
|
### Checks
|
|
300
395
|
|
|
@@ -303,7 +398,7 @@ yarn typecheck
|
|
|
303
398
|
yarn lint
|
|
304
399
|
yarn test # Jest: the JavaScript layer, with the native module mocked
|
|
305
400
|
yarn test:ios # the iOS APNs-hex parser, compiled with swiftc (macOS)
|
|
306
|
-
cd example/android && ./gradlew :
|
|
401
|
+
cd example/android && ./gradlew :pushpilotai_react-native:testDebugUnitTest # the Android receiver's data filter
|
|
307
402
|
```
|
|
308
403
|
|
|
309
404
|
## Releasing
|
package/android/build.gradle
CHANGED
|
@@ -4,13 +4,18 @@ import ai.pushpilot.sdk.PushPilot
|
|
|
4
4
|
import ai.pushpilot.sdk.TappedNotification
|
|
5
5
|
import android.app.Activity
|
|
6
6
|
import android.content.Intent
|
|
7
|
+
import android.util.Log
|
|
8
|
+
import android.view.Choreographer
|
|
7
9
|
import com.facebook.react.bridge.ActivityEventListener
|
|
8
10
|
import com.facebook.react.bridge.Arguments
|
|
9
11
|
import com.facebook.react.bridge.LifecycleEventListener
|
|
12
|
+
import com.facebook.react.bridge.Promise
|
|
10
13
|
import com.facebook.react.bridge.ReactApplicationContext
|
|
11
14
|
import com.facebook.react.bridge.ReadableArray
|
|
12
15
|
import com.facebook.react.bridge.ReadableMap
|
|
16
|
+
import com.facebook.react.bridge.UiThreadUtil
|
|
13
17
|
import com.facebook.react.modules.core.DeviceEventManagerModule
|
|
18
|
+
import com.facebook.react.uimanager.UIManagerHelper
|
|
14
19
|
|
|
15
20
|
/** Passes each JavaScript call straight to the native PushPilot SDK, and tapped pushes back to JavaScript. */
|
|
16
21
|
class PushPilotModule(reactContext: ReactApplicationContext) :
|
|
@@ -28,10 +33,19 @@ class PushPilotModule(reactContext: ReactApplicationContext) :
|
|
|
28
33
|
/** Starts the SDK (a null base URL means its default server); then taps that waited for JavaScript go to it. */
|
|
29
34
|
override fun initialize(sdkKey: String, baseUrl: String?) {
|
|
30
35
|
PushPilot.init(reactApplicationContext.applicationContext, sdkKey, baseUrl)
|
|
36
|
+
// JavaScript's init runs after the activity resumed, which the SDK's lifecycle watcher missed.
|
|
37
|
+
reactApplicationContext.currentActivity?.let(PushPilot::setCurrentActivity)
|
|
31
38
|
PushPilotTaps.opened(reactApplicationContext.currentActivity?.intent)
|
|
32
39
|
PushPilotTaps.attach(this)
|
|
33
40
|
}
|
|
34
41
|
|
|
42
|
+
/** Same as [initialize]: the App Group is for iOS live activities and has no use on Android. */
|
|
43
|
+
override fun initializeWithAppGroup(sdkKey: String, baseUrl: String?, appGroup: String) =
|
|
44
|
+
initialize(sdkKey, baseUrl)
|
|
45
|
+
|
|
46
|
+
/** Android needs no URL handling for live activities (the SDK opens their links), so the URL comes back unchanged. */
|
|
47
|
+
override fun handleLiveActivityURL(url: String, promise: Promise) = promise.resolve(url)
|
|
48
|
+
|
|
35
49
|
/** Forwards the Firebase Installation ID or FCM token, or null to clear it. */
|
|
36
50
|
override fun setPushToken(token: String?) = PushPilot.setPushToken(token)
|
|
37
51
|
|
|
@@ -51,6 +65,34 @@ class PushPilotModule(reactContext: ReactApplicationContext) :
|
|
|
51
65
|
/** Deletes this installation and clears local SDK state. */
|
|
52
66
|
override fun forget() = PushPilot.forget()
|
|
53
67
|
|
|
68
|
+
/** Shows a cached in-app message on the main thread, where the SDK requires it, and resolves whether one is on screen. */
|
|
69
|
+
override fun showInApp(name: String, promise: Promise) {
|
|
70
|
+
UiThreadUtil.runOnUiThread { promise.resolve(PushPilot.showInApp(name)) }
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
/** Looks the view up by its React tag and names it for coach marks; a tag with no native view is logged and ignored. */
|
|
74
|
+
override fun markView(viewTag: Double, name: String) {
|
|
75
|
+
onNextFrame {
|
|
76
|
+
val tag = viewTag.toInt()
|
|
77
|
+
val view = UIManagerHelper.getUIManagerForReactTag(reactApplicationContext, tag)?.resolveView(tag)
|
|
78
|
+
if (view != null) PushPilot.markView(view, name)
|
|
79
|
+
else Log.w(TAG, "markView ignored: no native view for that ref (is it mounted, with collapsable={false}?)")
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
/** Forgets the named view; on the same queue as [markView], so an earlier mark never lands after it. */
|
|
84
|
+
override fun unmarkView(name: String) {
|
|
85
|
+
onNextFrame { PushPilot.unmarkView(name) }
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
/**
|
|
89
|
+
* Runs [block] on the UI thread in the next frame: Fabric mounts a commit's views from a frame callback it
|
|
90
|
+
* keeps posted ahead of this one, so a ref marked in an effect right after render has its native view.
|
|
91
|
+
*/
|
|
92
|
+
private fun onNextFrame(block: () -> Unit) {
|
|
93
|
+
UiThreadUtil.runOnUiThread { Choreographer.getInstance().postFrameCallback { block() } }
|
|
94
|
+
}
|
|
95
|
+
|
|
54
96
|
/** JavaScript set (true) or cleared its link handler; the SDK's links come here only while one is set. */
|
|
55
97
|
override fun setLinkHandlerEnabled(enabled: Boolean) {
|
|
56
98
|
wantsLinks = enabled
|
|
@@ -105,5 +147,6 @@ class PushPilotModule(reactContext: ReactApplicationContext) :
|
|
|
105
147
|
|
|
106
148
|
companion object {
|
|
107
149
|
const val NAME = NativePushPilotSpec.NAME
|
|
150
|
+
private const val TAG = "PushPilot"
|
|
108
151
|
}
|
|
109
152
|
}
|
package/ios/RNPushPilot.mm
CHANGED
|
@@ -126,7 +126,59 @@ RCT_EXPORT_METHOD(setTapHandlerEnabled:(BOOL)enabled)
|
|
|
126
126
|
// to the handlers JavaScript set before init.
|
|
127
127
|
RCT_EXPORT_METHOD(initialize:(NSString *)sdkKey baseUrl:(NSString *)baseUrl)
|
|
128
128
|
{
|
|
129
|
-
[
|
|
129
|
+
[self startWithSdkKey:sdkKey baseUrl:baseUrl appGroup:nil];
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
// Starts the SDK as initialize does, with the App Group shared with the app's Widget Extension.
|
|
133
|
+
RCT_EXPORT_METHOD(initializeWithAppGroup:(NSString *)sdkKey baseUrl:(NSString *)baseUrl appGroup:(NSString *)appGroup)
|
|
134
|
+
{
|
|
135
|
+
[self startWithSdkKey:sdkKey baseUrl:baseUrl appGroup:appGroup];
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
// Records a live activity tap and resolves to the activity's own link (nil when it has none); other URLs unchanged.
|
|
139
|
+
RCT_EXPORT_METHOD(handleLiveActivityURL:(NSString *)url
|
|
140
|
+
resolve:(RCTPromiseResolveBlock)resolve
|
|
141
|
+
reject:(RCTPromiseRejectBlock)reject)
|
|
142
|
+
{
|
|
143
|
+
resolve([RNPushPilotBridge handleLiveActivityURL:url]);
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
// Shows a cached in-app message on the main thread, where the SDK requires it, and resolves whether one is on screen.
|
|
147
|
+
RCT_EXPORT_METHOD(showInApp:(NSString *)name
|
|
148
|
+
resolve:(RCTPromiseResolveBlock)resolve
|
|
149
|
+
reject:(RCTPromiseRejectBlock)reject)
|
|
150
|
+
{
|
|
151
|
+
dispatch_async(dispatch_get_main_queue(), ^{
|
|
152
|
+
resolve(@([RNPushPilotBridge showInApp:name]));
|
|
153
|
+
});
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
// Looks the view up by its React tag on the main thread, after views already queued for mounting, and names it
|
|
157
|
+
// for coach marks. A tag with no native view is logged and ignored.
|
|
158
|
+
RCT_EXPORT_METHOD(markView:(double)viewTag name:(NSString *)name)
|
|
159
|
+
{
|
|
160
|
+
[self.viewRegistry_DEPRECATED addUIBlock:^(RCTViewRegistry *registry) {
|
|
161
|
+
UIView *view = [registry viewForReactTag:@(viewTag)];
|
|
162
|
+
if (view) {
|
|
163
|
+
[RNPushPilotBridge markView:view name:name];
|
|
164
|
+
} else {
|
|
165
|
+
NSLog(@"[PushPilot] markView ignored: no native view for that ref (is it mounted, with collapsable={false}?)");
|
|
166
|
+
}
|
|
167
|
+
}];
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
// Forgets the named view; on the main queue like markView, so an earlier mark never lands after it.
|
|
171
|
+
RCT_EXPORT_METHOD(unmarkView:(NSString *)name)
|
|
172
|
+
{
|
|
173
|
+
dispatch_async(dispatch_get_main_queue(), ^{
|
|
174
|
+
[RNPushPilotBridge unmarkViewWithName:name];
|
|
175
|
+
});
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
// The work of both initialize calls; a nil App Group means none.
|
|
179
|
+
- (void)startWithSdkKey:(NSString *)sdkKey baseUrl:(NSString *)baseUrl appGroup:(NSString *)appGroup
|
|
180
|
+
{
|
|
181
|
+
[RNPushPilotBridge startWithSdkKey:sdkKey baseUrl:baseUrl appGroup:appGroup];
|
|
130
182
|
dispatch_async(dispatch_get_main_queue(), ^{
|
|
131
183
|
tapModule = self;
|
|
132
184
|
NSArray *waiting = [waitingTaps copy];
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import Foundation
|
|
2
2
|
import PushPilot
|
|
3
|
+
import UIKit
|
|
3
4
|
import UserNotifications
|
|
4
5
|
|
|
5
6
|
/// Calls the Swift-only PushPilot SDK for the Objective-C++ module, which cannot import it directly.
|
|
@@ -7,10 +8,18 @@ import UserNotifications
|
|
|
7
8
|
@objc(RNPushPilotBridge)
|
|
8
9
|
public final class RNPushPilotBridge: NSObject {
|
|
9
10
|
/// Starts the SDK. A base URL that is not a URL is logged and ignored rather than silently using the default server.
|
|
10
|
-
|
|
11
|
-
|
|
11
|
+
/// `appGroup` is the App Group shared with the Widget Extension, or nil.
|
|
12
|
+
@objc public static func start(sdkKey: String, baseUrl: String?, appGroup: String?) {
|
|
13
|
+
guard let baseUrl else { return PushPilot.initialize(sdkKey: sdkKey, appGroup: appGroup) }
|
|
12
14
|
guard let url = URL(string: baseUrl) else { return NSLog("[PushPilot] init ignored: baseUrl is not a URL") }
|
|
13
|
-
PushPilot.initialize(sdkKey: sdkKey, baseUrl: url)
|
|
15
|
+
PushPilot.initialize(sdkKey: sdkKey, baseUrl: url, appGroup: appGroup)
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
/// For a URL the app opened: a live activity tap is recorded and its own link returned (nil when it has
|
|
19
|
+
/// none). Any other URL, including one that does not parse, comes back unchanged.
|
|
20
|
+
@objc public static func handleLiveActivityURL(_ url: String) -> String? {
|
|
21
|
+
guard let parsed = URL(string: url) else { return url }
|
|
22
|
+
return PushPilot.handleLiveActivityURL(parsed)?.absoluteString
|
|
14
23
|
}
|
|
15
24
|
|
|
16
25
|
/// Call from `application(_:didRegisterForRemoteNotificationsWithDeviceToken:)` with the token as iOS gives it.
|
|
@@ -59,6 +68,21 @@ public final class RNPushPilotBridge: NSObject {
|
|
|
59
68
|
RNPushPilotNotifications.handle(response)
|
|
60
69
|
}
|
|
61
70
|
|
|
71
|
+
/// Shows the first eligible cached in-app message with this trigger name; returns whether one is on screen.
|
|
72
|
+
@MainActor @objc public static func showInApp(_ name: String) -> Bool {
|
|
73
|
+
PushPilot.showInApp(name)
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
/// Names a view for coach-mark messages whose target is `name`; the SDK holds it weakly.
|
|
77
|
+
@MainActor @objc public static func markView(_ view: UIView, name: String) {
|
|
78
|
+
PushPilot.markView(view, name: name)
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
/// Forgets the view marked with `name`.
|
|
82
|
+
@MainActor @objc public static func unmarkView(name: String) {
|
|
83
|
+
PushPilot.unmarkView(name: name)
|
|
84
|
+
}
|
|
85
|
+
|
|
62
86
|
/// Sends the links of tapped PushPilot pushes to `handler` on the main thread instead of opening them.
|
|
63
87
|
@objc public static func setLinkHandler(_ handler: @escaping (URL) -> Void) {
|
|
64
88
|
PushPilot.setLinkHandler(handler)
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["TurboModuleRegistry","get"],"sourceRoot":"../../src","sources":["NativePushPilot.ts"],"mappings":";;AAAA,SACEA,mBAAmB,QAGd,cAAc;;AAErB;;
|
|
1
|
+
{"version":3,"names":["TurboModuleRegistry","get"],"sourceRoot":"../../src","sources":["NativePushPilot.ts"],"mappings":";;AAAA,SACEA,mBAAmB,QAGd,cAAc;;AAErB;;AA+BA;AACA,eAAeA,mBAAmB,CAACC,GAAG,CAAO,WAAW,CAAC","ignoreList":[]}
|
package/lib/module/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
-
import { NativeEventEmitter, Platform } from 'react-native';
|
|
3
|
+
import { NativeEventEmitter, Platform, findNodeHandle } from 'react-native';
|
|
4
4
|
import Native from "./NativePushPilot.js";
|
|
5
5
|
|
|
6
6
|
/** A custom attribute value; `null` removes the attribute. Pass dates as RFC 3339 strings. */
|
|
@@ -38,7 +38,24 @@ function setHandler(event, handler, enable) {
|
|
|
38
38
|
const PushPilot = {
|
|
39
39
|
/** Starts the SDK with the app's public SDK key. Later calls are ignored; earlier calls are queued. */
|
|
40
40
|
init(sdkKey, options) {
|
|
41
|
-
|
|
41
|
+
const baseUrl = options?.baseUrl ?? null;
|
|
42
|
+
const appGroup = options?.appGroup;
|
|
43
|
+
call('init', n => appGroup ? n.initializeWithAppGroup(sdkKey, baseUrl, appGroup) : n.initialize(sdkKey, baseUrl));
|
|
44
|
+
},
|
|
45
|
+
/**
|
|
46
|
+
* Pass every URL your app is opened with (React Native's `Linking`). For a tap on an iOS live
|
|
47
|
+
* activity it records the click once and resolves to the activity's own link without PushPilot's
|
|
48
|
+
* marker, or `null` when the activity has none (just show the app). Any other URL, and every URL on
|
|
49
|
+
* Android, resolves unchanged. Never rejects: on a failure it resolves to the URL as given.
|
|
50
|
+
*/
|
|
51
|
+
async handleLiveActivityURL(url) {
|
|
52
|
+
try {
|
|
53
|
+
if (Native) return await Native.handleLiveActivityURL(url);
|
|
54
|
+
console.warn('[PushPilot] handleLiveActivityURL ignored: the native module is not linked. Rebuild the app (Expo Go is not supported).');
|
|
55
|
+
} catch (e) {
|
|
56
|
+
console.warn(`[PushPilot] handleLiveActivityURL failed: ${String(e)}`);
|
|
57
|
+
}
|
|
58
|
+
return url;
|
|
42
59
|
},
|
|
43
60
|
/**
|
|
44
61
|
* Passes the push identifier; `null` clears it.
|
|
@@ -91,6 +108,38 @@ const PushPilot = {
|
|
|
91
108
|
setTapHandler(handler) {
|
|
92
109
|
setHandler('PushPilotTap', handler, (n, on) => n.setTapHandlerEnabled(on));
|
|
93
110
|
},
|
|
111
|
+
/**
|
|
112
|
+
* Shows the first eligible cached in-app message whose trigger name is `name` and resolves to whether
|
|
113
|
+
* one is now on screen: `false` when none is cached and eligible, another message is showing, or the
|
|
114
|
+
* SDK has not started. No network call. Never rejects: on a failure it resolves to `false`.
|
|
115
|
+
*/
|
|
116
|
+
async showInApp(name) {
|
|
117
|
+
try {
|
|
118
|
+
if (Native) return await Native.showInApp(name);
|
|
119
|
+
console.warn('[PushPilot] showInApp ignored: the native module is not linked. Rebuild the app (Expo Go is not supported).');
|
|
120
|
+
} catch (e) {
|
|
121
|
+
console.warn(`[PushPilot] showInApp failed: ${String(e)}`);
|
|
122
|
+
}
|
|
123
|
+
return false;
|
|
124
|
+
},
|
|
125
|
+
/**
|
|
126
|
+
* Names a mounted view for coach-mark messages whose target is `name`: pass its `ref` (or a view tag
|
|
127
|
+
* from `findNodeHandle`). Give a plain `<View>` `collapsable={false}` so it has a native view. The SDK
|
|
128
|
+
* holds the view weakly; a later view with the same name replaces it.
|
|
129
|
+
*/
|
|
130
|
+
// `any`: refs of every host component type (View, Pressable, TextInput...) are accepted.
|
|
131
|
+
markView(ref, name) {
|
|
132
|
+
const tag = typeof ref === 'number' ? ref : findNodeHandle(ref.current);
|
|
133
|
+
if (tag == null) {
|
|
134
|
+
console.warn('[PushPilot] markView ignored: the ref has no mounted native view yet.');
|
|
135
|
+
return;
|
|
136
|
+
}
|
|
137
|
+
call('markView', n => n.markView(tag, name));
|
|
138
|
+
},
|
|
139
|
+
/** Forgets the view marked with `name`. */
|
|
140
|
+
unmarkView(name) {
|
|
141
|
+
call('unmarkView', n => n.unmarkView(name));
|
|
142
|
+
},
|
|
94
143
|
/** True when a received push's data came from PushPilot. Same rule as the native SDKs; no native call. */
|
|
95
144
|
handleMessage(data) {
|
|
96
145
|
return data?.source === 'pushpilot';
|
package/lib/module/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["NativeEventEmitter","Platform","Native","call","name","run","console","warn","e","String","APNS_HEX","subscriptions","setHandler","event","handler","enable","n","remove","addListener","undefined","PushPilot","init","sdkKey","options","initialize","
|
|
1
|
+
{"version":3,"names":["NativeEventEmitter","Platform","findNodeHandle","Native","call","name","run","console","warn","e","String","APNS_HEX","subscriptions","setHandler","event","handler","enable","n","remove","addListener","undefined","PushPilot","init","sdkKey","options","baseUrl","appGroup","initializeWithAppGroup","initialize","handleLiveActivityURL","url","setPushToken","token","OS","test","setExternalUserId","id","setAttributes","attributes","setTopics","topics","logout","forget","setLinkHandler","on","setLinkHandlerEnabled","setTapHandler","setTapHandlerEnabled","showInApp","markView","ref","tag","current","unmarkView","handleMessage","data","source"],"sourceRoot":"../../src","sources":["index.tsx"],"mappings":";;AACA,SACEA,kBAAkB,EAClBC,QAAQ,EACRC,cAAc,QAET,cAAc;AACrB,OAAOC,MAAM,MAAqB,sBAAmB;;AAErD;;AAGA;;AAQA;;AAWA;AACA,SAASC,IAAIA,CAACC,IAAY,EAAEC,GAA2B,EAAQ;EAC7D,IAAI;IACF,IA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ChD,CAAC;EAED;EACAgD,UAAUA,CAAChD,IAAY,EAAQ;IAC7BD,IAAI,CAAC,YAAY,EAAGa,CAAC,IAAKA,CAAC,CAACoC,UAAU,CAAChD,IAAI,CAAC,CAAC;EAC/C,CAAC;EAED;EACAiD,aAAaA,CAACC,IAAmD,EAAW;IAC1E,OAAOA,IAAI,EAAEC,MAAM,KAAK,WAAW;EACrC;AACF,CAAC;AAED,eAAenC,SAAS","ignoreList":[]}
|
|
@@ -1,12 +1,17 @@
|
|
|
1
1
|
import { type CodegenTypes, type TurboModule } from 'react-native';
|
|
2
2
|
export interface Spec extends TurboModule {
|
|
3
3
|
initialize(sdkKey: string, baseUrl: string | null): void;
|
|
4
|
+
initializeWithAppGroup(sdkKey: string, baseUrl: string | null, appGroup: string): void;
|
|
5
|
+
handleLiveActivityURL(url: string): Promise<string | null>;
|
|
4
6
|
setPushToken(token: string | null): void;
|
|
5
7
|
setExternalUserId(id: string | null): void;
|
|
6
8
|
setAttributes(attributes: CodegenTypes.UnsafeObject): void;
|
|
7
9
|
setTopics(topics: string[]): void;
|
|
8
10
|
logout(): void;
|
|
9
11
|
forget(): void;
|
|
12
|
+
showInApp(name: string): Promise<boolean>;
|
|
13
|
+
markView(viewTag: number, name: string): void;
|
|
14
|
+
unmarkView(name: string): void;
|
|
10
15
|
setLinkHandlerEnabled(enabled: boolean): void;
|
|
11
16
|
setTapHandlerEnabled(enabled: boolean): void;
|
|
12
17
|
addListener(eventName: string): void;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"NativePushPilot.d.ts","sourceRoot":"","sources":["../../../src/NativePushPilot.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,KAAK,YAAY,EACjB,KAAK,WAAW,EACjB,MAAM,cAAc,CAAC;AAGtB,MAAM,WAAW,IAAK,SAAQ,WAAW;IAEvC,UAAU,CAAC,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,GAAG,IAAI,GAAG,IAAI,CAAC;
|
|
1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IAAI,CAAC;CACtC;;AAGD,wBAA0D"}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { RefObject } from 'react';
|
|
1
2
|
/** A custom attribute value; `null` removes the attribute. Pass dates as RFC 3339 strings. */
|
|
2
3
|
export type AttributeValue = string | number | boolean | null;
|
|
3
4
|
/** A tapped PushPilot push that opened the app. */
|
|
@@ -11,10 +12,22 @@ export interface TappedNotification {
|
|
|
11
12
|
export interface InitOptions {
|
|
12
13
|
/** Your own server, for self-hosted PushPilot. Defaults to https://pushpilot.ai. */
|
|
13
14
|
baseUrl?: string;
|
|
15
|
+
/**
|
|
16
|
+
* iOS: the App Group shared with your Widget Extension, so images in live activity layouts can be
|
|
17
|
+
* shown. Pass the same id to `PushPilotLiveActivityWidget(appGroup:)`. Ignored on Android.
|
|
18
|
+
*/
|
|
19
|
+
appGroup?: string;
|
|
14
20
|
}
|
|
15
21
|
declare const PushPilot: {
|
|
16
22
|
/** Starts the SDK with the app's public SDK key. Later calls are ignored; earlier calls are queued. */
|
|
17
23
|
init(sdkKey: string, options?: InitOptions): void;
|
|
24
|
+
/**
|
|
25
|
+
* Pass every URL your app is opened with (React Native's `Linking`). For a tap on an iOS live
|
|
26
|
+
* activity it records the click once and resolves to the activity's own link without PushPilot's
|
|
27
|
+
* marker, or `null` when the activity has none (just show the app). Any other URL, and every URL on
|
|
28
|
+
* Android, resolves unchanged. Never rejects: on a failure it resolves to the URL as given.
|
|
29
|
+
*/
|
|
30
|
+
handleLiveActivityURL(url: string): Promise<string | null>;
|
|
18
31
|
/**
|
|
19
32
|
* Passes the push identifier; `null` clears it.
|
|
20
33
|
* - Android: the Firebase Installation ID from `register` / `onRegistered` where your Firebase
|
|
@@ -46,6 +59,20 @@ declare const PushPilot: {
|
|
|
46
59
|
* Set it before `init` to also get the tap that launched the app; each tap arrives once.
|
|
47
60
|
*/
|
|
48
61
|
setTapHandler(handler: ((tap: TappedNotification) => void) | null): void;
|
|
62
|
+
/**
|
|
63
|
+
* Shows the first eligible cached in-app message whose trigger name is `name` and resolves to whether
|
|
64
|
+
* one is now on screen: `false` when none is cached and eligible, another message is showing, or the
|
|
65
|
+
* SDK has not started. No network call. Never rejects: on a failure it resolves to `false`.
|
|
66
|
+
*/
|
|
67
|
+
showInApp(name: string): Promise<boolean>;
|
|
68
|
+
/**
|
|
69
|
+
* Names a mounted view for coach-mark messages whose target is `name`: pass its `ref` (or a view tag
|
|
70
|
+
* from `findNodeHandle`). Give a plain `<View>` `collapsable={false}` so it has a native view. The SDK
|
|
71
|
+
* holds the view weakly; a later view with the same name replaces it.
|
|
72
|
+
*/
|
|
73
|
+
markView(ref: RefObject<any> | number, name: string): void;
|
|
74
|
+
/** Forgets the view marked with `name`. */
|
|
75
|
+
unmarkView(name: string): void;
|
|
49
76
|
/** True when a received push's data came from PushPilot. Same rule as the native SDKs; no native call. */
|
|
50
77
|
handleMessage(data: {
|
|
51
78
|
[key: string]: unknown;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/index.tsx"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/index.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AASvC,8FAA8F;AAC9F,MAAM,MAAM,cAAc,GAAG,MAAM,GAAG,MAAM,GAAG,OAAO,GAAG,IAAI,CAAC;AAE9D,mDAAmD;AACnD,MAAM,WAAW,kBAAkB;IACjC,0EAA0E;IAC1E,cAAc,EAAE,MAAM,CAAC;IACvB,sDAAsD;IACtD,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;CAC9B;AAED,oCAAoC;AACpC,MAAM,WAAW,WAAW;IAC1B,oFAAoF;IACpF,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB;;;OAGG;IACH,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB;AAwCD,QAAA,MAAM,SAAS;IACb,uGAAuG;iBAC1F,MAAM,YAAY,WAAW,GAAG,IAAI;IAUjD;;;;;OAKG;+BAC8B,MAAM,GAAG,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC;IAYhE;;;;;;;;OAQG;wBACiB,MAAM,GAAG,IAAI,GAAG,IAAI;IAUxC,iFAAiF;0BAC3D,MAAM,GAAG,IAAI,GAAG,IAAI;IAI1C,0DAA0D;8BAChC,MAAM,CAAC,MAAM,EAAE,cAAc,CAAC,GAAG,IAAI;IAI/D,+CAA+C;sBAC7B,MAAM,EAAE,GAAG,IAAI;IAIjC,2FAA2F;cACjF,IAAI;IAId,+EAA+E;cACrE,IAAI;IAId;;;;OAIG;4BACqB,CAAC,CAAC,GAAG,EAAE,MAAM,KAAK,IAAI,CAAC,GAAG,IAAI,GAAG,IAAI;IAM7D;;;OAGG;2BACoB,CAAC,CAAC,GAAG,EAAE,kBAAkB,KAAK,IAAI,CAAC,GAAG,IAAI,GAAG,IAAI;IAIxE;;;;OAIG;oBACmB,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC;IAY/C;;;;OAIG;kBAEW,SAAS,CAAC,GAAG,CAAC,GAAG,MAAM,QAAQ,MAAM,GAAG,IAAI;IAW1D,2CAA2C;qBAC1B,MAAM,GAAG,IAAI;IAI9B,0GAA0G;wBACtF;QAAE,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAA;KAAE,GAAG,IAAI,GAAG,SAAS,GAAG,OAAO;CAG5E,CAAC;AAEF,eAAe,SAAS,CAAC"}
|
package/package.json
CHANGED
package/src/NativePushPilot.ts
CHANGED
|
@@ -8,12 +8,25 @@ import {
|
|
|
8
8
|
export interface Spec extends TurboModule {
|
|
9
9
|
// Named `initialize` because Objective-C reserves methods starting with `init`.
|
|
10
10
|
initialize(sdkKey: string, baseUrl: string | null): void;
|
|
11
|
+
// `initialize` plus the App Group shared with the iOS Widget Extension; Android ignores the group.
|
|
12
|
+
initializeWithAppGroup(
|
|
13
|
+
sdkKey: string,
|
|
14
|
+
baseUrl: string | null,
|
|
15
|
+
appGroup: string
|
|
16
|
+
): void;
|
|
17
|
+
// The link of a live activity tap without PushPilot's marker, or null; other URLs come back unchanged.
|
|
18
|
+
handleLiveActivityURL(url: string): Promise<string | null>;
|
|
11
19
|
setPushToken(token: string | null): void;
|
|
12
20
|
setExternalUserId(id: string | null): void;
|
|
13
21
|
setAttributes(attributes: CodegenTypes.UnsafeObject): void;
|
|
14
22
|
setTopics(topics: string[]): void;
|
|
15
23
|
logout(): void;
|
|
16
24
|
forget(): void;
|
|
25
|
+
// The first eligible cached in-app message with this trigger name; resolves whether it is now on screen.
|
|
26
|
+
showInApp(name: string): Promise<boolean>;
|
|
27
|
+
// Names the native view with this React tag (from findNodeHandle) for coach-mark messages, or forgets one.
|
|
28
|
+
markView(viewTag: number, name: string): void;
|
|
29
|
+
unmarkView(name: string): void;
|
|
17
30
|
// Whether JavaScript has a link handler / tap handler; native sends those events only while it does.
|
|
18
31
|
setLinkHandlerEnabled(enabled: boolean): void;
|
|
19
32
|
setTapHandlerEnabled(enabled: boolean): void;
|
package/src/index.tsx
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
|
+
import type { RefObject } from 'react';
|
|
1
2
|
import {
|
|
2
3
|
NativeEventEmitter,
|
|
3
4
|
Platform,
|
|
5
|
+
findNodeHandle,
|
|
4
6
|
type EmitterSubscription,
|
|
5
7
|
} from 'react-native';
|
|
6
8
|
import Native, { type Spec } from './NativePushPilot';
|
|
@@ -20,6 +22,11 @@ export interface TappedNotification {
|
|
|
20
22
|
export interface InitOptions {
|
|
21
23
|
/** Your own server, for self-hosted PushPilot. Defaults to https://pushpilot.ai. */
|
|
22
24
|
baseUrl?: string;
|
|
25
|
+
/**
|
|
26
|
+
* iOS: the App Group shared with your Widget Extension, so images in live activity layouts can be
|
|
27
|
+
* shown. Pass the same id to `PushPilotLiveActivityWidget(appGroup:)`. Ignored on Android.
|
|
28
|
+
*/
|
|
29
|
+
appGroup?: string;
|
|
23
30
|
}
|
|
24
31
|
|
|
25
32
|
// Runs one native call, logging instead of throwing so the SDK can never crash the app.
|
|
@@ -63,7 +70,31 @@ function setHandler<E extends keyof Events>(
|
|
|
63
70
|
const PushPilot = {
|
|
64
71
|
/** Starts the SDK with the app's public SDK key. Later calls are ignored; earlier calls are queued. */
|
|
65
72
|
init(sdkKey: string, options?: InitOptions): void {
|
|
66
|
-
|
|
73
|
+
const baseUrl = options?.baseUrl ?? null;
|
|
74
|
+
const appGroup = options?.appGroup;
|
|
75
|
+
call('init', (n) =>
|
|
76
|
+
appGroup
|
|
77
|
+
? n.initializeWithAppGroup(sdkKey, baseUrl, appGroup)
|
|
78
|
+
: n.initialize(sdkKey, baseUrl)
|
|
79
|
+
);
|
|
80
|
+
},
|
|
81
|
+
|
|
82
|
+
/**
|
|
83
|
+
* Pass every URL your app is opened with (React Native's `Linking`). For a tap on an iOS live
|
|
84
|
+
* activity it records the click once and resolves to the activity's own link without PushPilot's
|
|
85
|
+
* marker, or `null` when the activity has none (just show the app). Any other URL, and every URL on
|
|
86
|
+
* Android, resolves unchanged. Never rejects: on a failure it resolves to the URL as given.
|
|
87
|
+
*/
|
|
88
|
+
async handleLiveActivityURL(url: string): Promise<string | null> {
|
|
89
|
+
try {
|
|
90
|
+
if (Native) return await Native.handleLiveActivityURL(url);
|
|
91
|
+
console.warn(
|
|
92
|
+
'[PushPilot] handleLiveActivityURL ignored: the native module is not linked. Rebuild the app (Expo Go is not supported).'
|
|
93
|
+
);
|
|
94
|
+
} catch (e) {
|
|
95
|
+
console.warn(`[PushPilot] handleLiveActivityURL failed: ${String(e)}`);
|
|
96
|
+
}
|
|
97
|
+
return url;
|
|
67
98
|
},
|
|
68
99
|
|
|
69
100
|
/**
|
|
@@ -129,6 +160,45 @@ const PushPilot = {
|
|
|
129
160
|
setHandler('PushPilotTap', handler, (n, on) => n.setTapHandlerEnabled(on));
|
|
130
161
|
},
|
|
131
162
|
|
|
163
|
+
/**
|
|
164
|
+
* Shows the first eligible cached in-app message whose trigger name is `name` and resolves to whether
|
|
165
|
+
* one is now on screen: `false` when none is cached and eligible, another message is showing, or the
|
|
166
|
+
* SDK has not started. No network call. Never rejects: on a failure it resolves to `false`.
|
|
167
|
+
*/
|
|
168
|
+
async showInApp(name: string): Promise<boolean> {
|
|
169
|
+
try {
|
|
170
|
+
if (Native) return await Native.showInApp(name);
|
|
171
|
+
console.warn(
|
|
172
|
+
'[PushPilot] showInApp ignored: the native module is not linked. Rebuild the app (Expo Go is not supported).'
|
|
173
|
+
);
|
|
174
|
+
} catch (e) {
|
|
175
|
+
console.warn(`[PushPilot] showInApp failed: ${String(e)}`);
|
|
176
|
+
}
|
|
177
|
+
return false;
|
|
178
|
+
},
|
|
179
|
+
|
|
180
|
+
/**
|
|
181
|
+
* Names a mounted view for coach-mark messages whose target is `name`: pass its `ref` (or a view tag
|
|
182
|
+
* from `findNodeHandle`). Give a plain `<View>` `collapsable={false}` so it has a native view. The SDK
|
|
183
|
+
* holds the view weakly; a later view with the same name replaces it.
|
|
184
|
+
*/
|
|
185
|
+
// `any`: refs of every host component type (View, Pressable, TextInput...) are accepted.
|
|
186
|
+
markView(ref: RefObject<any> | number, name: string): void {
|
|
187
|
+
const tag = typeof ref === 'number' ? ref : findNodeHandle(ref.current);
|
|
188
|
+
if (tag == null) {
|
|
189
|
+
console.warn(
|
|
190
|
+
'[PushPilot] markView ignored: the ref has no mounted native view yet.'
|
|
191
|
+
);
|
|
192
|
+
return;
|
|
193
|
+
}
|
|
194
|
+
call('markView', (n) => n.markView(tag, name));
|
|
195
|
+
},
|
|
196
|
+
|
|
197
|
+
/** Forgets the view marked with `name`. */
|
|
198
|
+
unmarkView(name: string): void {
|
|
199
|
+
call('unmarkView', (n) => n.unmarkView(name));
|
|
200
|
+
},
|
|
201
|
+
|
|
132
202
|
/** True when a received push's data came from PushPilot. Same rule as the native SDKs; no native call. */
|
|
133
203
|
handleMessage(data: { [key: string]: unknown } | null | undefined): boolean {
|
|
134
204
|
return data?.source === 'pushpilot';
|