@pushpilotai/react-native 0.0.0-stage → 2.0.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/LICENSE ADDED
@@ -0,0 +1,201 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "[]"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright [yyyy] [name of copyright owner]
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.
@@ -0,0 +1,27 @@
1
+ require "json"
2
+
3
+ package = JSON.parse(File.read(File.join(__dir__, "package.json")))
4
+
5
+ Pod::Spec.new do |s|
6
+ s.name = "PushPilotReactNative"
7
+ s.version = package["version"]
8
+ s.summary = package["description"]
9
+ s.homepage = package["homepage"]
10
+ s.authors = package["author"]
11
+
12
+ s.platforms = { :ios => min_ios_version_supported }
13
+ s.source = { :git => "https://github.com/pushpilotai/pushpilot-react-native.git", :tag => "#{s.version}" }
14
+
15
+ s.source_files = "ios/**/*.{h,m,mm,swift}"
16
+ s.private_header_files = "ios/**/*.h"
17
+
18
+ # The native iOS SDK is a Swift package with no podspec; React Native adds it to the Pods project.
19
+ # To build against a local pushpilot-ios checkout instead, see README -> Local development.
20
+ spm_dependency(s,
21
+ url: "https://github.com/pushpilotai/pushpilot-ios.git",
22
+ requirement: { kind: "upToNextMajorVersion", minimumVersion: "2.0.0" },
23
+ products: ["PushPilot"]
24
+ )
25
+
26
+ install_modules_dependencies(s)
27
+ end
package/README.md CHANGED
@@ -1,3 +1,315 @@
1
- # Temporary Holding Version
1
+ # @pushpilotai/react-native
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
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
+
5
+ - A thin layer over the native [Android SDK](https://github.com/pushpilotai/pushpilot-android) (`ai.pushpilot:sdk` 2.0.0) and [iOS SDK](https://github.com/pushpilotai/pushpilot-ios) (Swift package `PushPilot` 2.0.0). Every call goes straight to them; they do all syncing, retrying, storage, display and validation.
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
+ - Never asks for notification permission. It reports whatever the user chose.
8
+ - Every call returns nothing and never throws into your app. Problems are logged.
9
+
10
+ ## Requirements
11
+
12
+ - React Native 0.81 or later. Built for the New Architecture; it also works with the New Architecture turned off on React Native 0.81, the last version that allows that.
13
+ - iOS 15.1 or later, Android 7 (API 24) or later (React Native's own minimums).
14
+ - A native build: a bare React Native app or an Expo development build. It cannot work in Expo Go, which has no way to add native code; there every call just logs a warning.
15
+
16
+ ## Install
17
+
18
+ ```bash
19
+ npm install @pushpilotai/react-native
20
+ ```
21
+
22
+ Then `cd ios && pod install`. Autolinking adds the native module on both platforms.
23
+
24
+ ## Integrate (bare React Native)
25
+
26
+ ### Both platforms
27
+
28
+ 1. **Create the app in PushPilot** (dashboard › Apps) and copy its public SDK key. For iOS this needs an APNs push project first; see [iOS](#ios) step 1.
29
+ 2. **Initialise once at startup**, at the top level of `index.js` or `App.tsx`:
30
+
31
+ ```tsx
32
+ import PushPilot from '@pushpilotai/react-native';
33
+
34
+ PushPilot.init('pp_sdk_...');
35
+ ```
36
+
37
+ 3. **Identify the user** after login with `PushPilot.setExternalUserId(user.id)` and call `PushPilot.logout()` at logout.
38
+ 4. **Ask for notification permission yourself**, when it suits your app (below for each platform). The SDK reads the result each time the app comes to the foreground.
39
+ 5. **Optional: handle taps in JavaScript.** By default a tapped PushPilot push opens its link through the system, or just your app when it has none. To route links yourself, or to read the push's custom `data`, set handlers **before `init`**, so the tap that launched a killed app reaches them too:
40
+
41
+ ```tsx
42
+ PushPilot.setLinkHandler((url) => {
43
+ // the tapped push's link: navigate to its screen instead of the system opening it
44
+ });
45
+ PushPilot.setTapHandler(({ notificationId, data }) => {
46
+ // every tap that opens the app, e.g. data.order_id
47
+ });
48
+ PushPilot.init('pp_sdk_...');
49
+ ```
50
+
51
+ Both work the same on Android and iOS. Taps that arrive before JavaScript has started wait for `init` and then go to the handlers set by then; each tap reaches each handler once. Without a link handler at that point, links open in the system; without a tap handler, taps are not reported. For a tap with a link, the tap handler runs first, then the link handler. [Tap details](#taps-on-android-and-ios).
52
+
53
+ Calls made before `init` are queued by the native SDKs and applied once it runs, so the order of these steps does not matter.
54
+
55
+ ### Android
56
+
57
+ 1. **Set up Firebase Cloud Messaging**, usually with [React Native Firebase](https://rnfirebase.io/messaging/usage): `@react-native-firebase/app` and `@react-native-firebase/messaging`, plus your `google-services.json`. Any library that brings in Firebase Messaging works.
58
+ 2. **Forward the push identifier** with `setPushToken`. Firebase is replacing FCM registration tokens with Firebase Installation IDs (FIDs); PushPilot accepts either. Pass only one kind. With React Native Firebase 27 or later, prefer the FID: add `"messaging_installation_id_enabled": true` under `"react-native"` in `firebase.json` (Expo: the messaging plugin's `installationIdEnabled: true`), then:
59
+
60
+ ```tsx
61
+ import { Platform } from 'react-native';
62
+ import { getMessaging, onRegistered, register } from '@react-native-firebase/messaging';
63
+
64
+ if (Platform.OS === 'android') {
65
+ const messaging = getMessaging();
66
+ onRegistered(messaging, PushPilot.setPushToken); // the current FID and every new one
67
+ register(messaging);
68
+ }
69
+ ```
70
+
71
+ Without that opt-in, or on older versions, forward the FCM token instead. The opt-in turns these calls off, so never mix the two:
72
+
73
+ ```tsx
74
+ import { getToken, onTokenRefresh } from '@react-native-firebase/messaging';
75
+
76
+ getToken(messaging).then(PushPilot.setPushToken);
77
+ onTokenRefresh(messaging, PushPilot.setPushToken);
78
+ ```
79
+
80
+ Firebase's "installation ID" (the FID) is a Firebase identifier you pass in as the push identifier. It is not PushPilot's own installation id, which the SDK creates and stores by itself.
81
+
82
+ 3. **Nothing else.** PushPilot pushes are shown by the SDK, with image and buttons, whether the app is open, in the background or killed ([how](#android-how-pushes-reach-the-sdk)). Do not show them yourself. In your own `onMessage` or `setBackgroundMessageHandler`, skip them:
83
+
84
+ ```tsx
85
+ onMessage(messaging, (message) => {
86
+ if (PushPilot.handleMessage(message.data)) return; // already shown by PushPilot
87
+ // your own pushes
88
+ });
89
+ ```
90
+
91
+ If you also have a native `FirebaseMessagingService`, do not call the Android SDK's `PushPilot.handleMessage` from it: the wrapper already does, and the push would be shown twice.
92
+
93
+ 4. **Permission:** `PermissionsAndroid.request('android.permission.POST_NOTIFICATIONS')` on Android 13 and later.
94
+
95
+ Tapping a PushPilot push records the click and opens its link, or your launcher activity when it has none. To route links or read the push's `data` in JavaScript, see [Both platforms](#both-platforms) step 5.
96
+
97
+ Optional: set the notification icon and channel name with the Android SDK's meta-data, described in its [Notifications](https://github.com/pushpilotai/pushpilot-android#notifications) section.
98
+
99
+ ### iOS
100
+
101
+ 1. **Give PushPilot your APNs key.** Create an APNs auth key (`.p8`) in your Apple Developer account and add it in the PushPilot dashboard as an APNs push project, with its Key ID and your Team ID. Create the iOS app on that project with your bundle id. The [iOS SDK README](https://github.com/pushpilotai/pushpilot-ios#integrate) has the exact steps. No Firebase is needed on iOS. If you keep React Native Firebase for Android only, you can drop it from iOS. List `@react-native-firebase/app` and `@react-native-firebase/messaging` with `platforms: { ios: null }` in `react-native.config.js`, as the example does.
102
+ 2. **Turn on Push Notifications** in your app target: *Signing & Capabilities › + Capability › Push Notifications*.
103
+ 3. **Hand PushPilot the device token** in your `AppDelegate`. This is the only native code PushPilot needs in the app:
104
+
105
+ ```swift
106
+ import PushPilotReactNative
107
+
108
+ // in your AppDelegate class:
109
+ func application(_ application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data) {
110
+ RNPushPilotBridge.setDeviceToken(deviceToken)
111
+ }
112
+ ```
113
+
114
+ In an Objective-C `AppDelegate.mm`: `#import <PushPilotReactNative/PushPilotReactNative-Swift.h>` and `[RNPushPilotBridge setDeviceToken:deviceToken];` in the same method. Only the Swift form is built in this repo's example.
115
+
116
+ 4. **Permission:** ask with whatever your app already uses (expo-notifications, React Native Firebase's `requestPermission`, or `UNUserNotificationCenter.requestAuthorization` in native code). You do not need to call `registerForRemoteNotifications`: the wrapper calls it at launch and each time the app becomes active, once notifications are allowed, so the token arrives as soon as the user says yes.
117
+ 5. **Taps need no code.** At launch the wrapper joins the `UNUserNotificationCenter` delegate chain, as React Native Firebase and expo-notifications do. It records clicks on PushPilot pushes, opens their links or passes them to `setLinkHandler`, reports them to `setTapHandler`, and passes every call on, unchanged, to the delegate that was set before it. If your own code sets that delegate *after* launch, it replaces the wrapper's. In that case call `RNPushPilotBridge.handleNotificationResponse(response)` from your delegate's `didReceive`; it does all of the above.
118
+ 6. **Optional: images and buttons**, with a [Notification Service Extension](#ios-notification-service-extension). Without one, PushPilot pushes arrive without them, and taps still work.
119
+
120
+ #### iOS Notification Service Extension
121
+
122
+ 1. In Xcode, open `ios/<App>.xcworkspace` and choose **File › New › Target… › Notification Service Extension**. Name it, for example, `NotificationService`. Keep its bundle id under the app's (`<app bundle id>.NotificationService`), set its deployment target to iOS 15.1 (the app's) and its signing team to the app's. When Xcode asks whether to activate the new scheme, choose **Cancel** so you keep building the app's scheme.
123
+ 2. Add the iOS SDK's package to the app's project: **File › Add Package Dependencies…**, enter the pushpilot-ios repository URL (while unpublished: **Add Local…** and pick your `pushpilot-ios` checkout), and add the **`PushPilotNotificationService`** library to the **extension target only**. Do not add `PushPilot` to the app target; the pod already brings it in.
124
+ 3. Replace the generated `NotificationService.swift` with:
125
+
126
+ ```swift
127
+ import PushPilotNotificationService
128
+ import UserNotifications
129
+
130
+ final class NotificationService: UNNotificationServiceExtension {
131
+ private let pushPilot = PushPilotServiceExtension()
132
+
133
+ override func didReceive(_ request: UNNotificationRequest,
134
+ withContentHandler contentHandler: @escaping (UNNotificationContent) -> Void) {
135
+ if pushPilot.didReceive(request, withContentHandler: contentHandler) { return }
136
+ contentHandler(request.content) // not a PushPilot push: deliver it as is
137
+ }
138
+
139
+ override func serviceExtensionTimeWillExpire() {
140
+ pushPilot.serviceExtensionTimeWillExpire()
141
+ }
142
+ }
143
+ ```
144
+
145
+ 4. Nothing in the `Podfile`: the extension uses no pods. `pod install` keeps the target as it is.
146
+
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
+
149
+ ## Integrate (Expo development build)
150
+
151
+ PushPilot has no Expo config plugin. What works without one:
152
+
153
+ 1. `npx expo install @pushpilotai/react-native`, then build a development build (`npx expo run:ios` / `npx expo run:android`, or `eas build --profile development`).
154
+ 2. **Android:** the wrapper's receiver shows PushPilot pushes natively, as in a bare app; no Android code is needed. What the app still has to do is get FCM into the app (your `google-services.json`) and forward a push identifier with `setPushToken`. Either set up React Native Firebase with its config plugins, as its Expo instructions at [rnfirebase.io](https://rnfirebase.io) describe, and forward the FID or token as above, or use expo-notifications: on Android its `getDevicePushTokenAsync()` returns the FCM token. expo-notifications no longer shows PushPilot pushes a second time: it displays a data-only message by itself only when the data has a `title` or `message` key (checked in 58.1.9), and PushPilot's data now carries only `source` and `pushpilot`. While the app is in the foreground it still passes the message to your `setNotificationHandler`, so return no banner or list entry there when `PushPilot.handleMessage(notification.request.content.data)` is true. This repo does not build an Expo app, so the Expo steps are not verified here.
155
+ 3. **iOS:** Expo regenerates the `AppDelegate`, so pass the token from JavaScript instead. expo-notifications gives the APNs token as hex, which `setPushToken` accepts on iOS:
156
+
157
+ ```tsx
158
+ import * as Notifications from 'expo-notifications';
159
+
160
+ if (Platform.OS === 'ios') {
161
+ const { status } = await Notifications.requestPermissionsAsync();
162
+ if (status === 'granted') {
163
+ const { data } = await Notifications.getDevicePushTokenAsync(); // hex APNs token
164
+ PushPilot.setPushToken(data);
165
+ }
166
+ }
167
+ ```
168
+
169
+ Use `getDevicePushTokenAsync` (the APNs token), not `getExpoPushTokenAsync` (Expo's own token, which PushPilot cannot use). Call it at every launch once permission is granted, so a changed token reaches PushPilot. Turn on push notifications for the app (expo-notifications' config plugin adds the `aps-environment` entitlement). Taps need no code: expo-notifications 58 chains to the delegate that was set before it, as the wrapper does, so both libraries get every tap whichever starts first, and `setLinkHandler` and `setTapHandler` work as in a bare app. React Native Firebase's `getAPNSToken()` returns the same token in uppercase hex, which is also accepted.
170
+ 4. **Images and buttons on iOS** need a Notification Service Extension target. An Expo app that regenerates its `ios/` folder can only add one with a config plugin, which PushPilot does not provide. Without it, PushPilot pushes still arrive and taps still work, without image or buttons.
171
+
172
+ ## Android: how pushes reach the SDK
173
+
174
+ The wrapper declares its own receiver, `PushPilotMessageReceiver`, for the broadcast Google Play services sends for every FCM message (`com.google.android.c2dm.intent.RECEIVE`, guarded by the `com.google.android.c2dm.permission.SEND` permission). React Native Firebase uses the same kind of receiver. Every receiver for that broadcast gets each message: Firebase's own `FirebaseMessagingService` and React Native Firebase still get it, alongside the wrapper's.
175
+
176
+ For each data message the receiver builds the data map as FCM's `RemoteMessage.getData()` does. It leaves out FCM's own `google.*`, `gcm.*`, `from` and `collapse_key` keys and ignores deletion and send-status broadcasts. A PushPilot message's data is just `source` = `pushpilot` and `pushpilot`, a JSON string with the title, body, link, buttons and your `data`, which only the SDK reads. It then calls the Android SDK's `handleMessage` on a background thread, keeping the broadcast alive with `goAsync()` while the image downloads. For a PushPilot push (`source` = `pushpilot`) the SDK reports `delivered` and shows the notification; anything else is ignored.
177
+
178
+ A push, a notification tap or a button press can start a killed app's process with no JavaScript. The SDK then starts itself from the SDK key and `baseUrl` that the last `init` saved, so their `delivered` and `clicked` events are still sent. The wrapper keeps nothing of its own for that.
179
+
180
+ A second component, `PushPilotStartupProvider`, runs when the process starts, before your `Application.onCreate` and before the SDK handles a tap. If the last JavaScript run had a link handler, it installs the wrapper's link handler in the SDK, so the tap that launched a killed app reaches JavaScript's handler (see [Taps](#taps-on-android-and-ios)). It saves only that yes/no, in the app's preferences file `ai.pushpilot.reactnative`.
181
+
182
+ Why this way:
183
+
184
+ - **It works with or without React Native Firebase, and needs no Firebase dependency in the wrapper.** It also works with any other FCM library, and with your own native `FirebaseMessagingService`. Overriding the app's messaging service would clash with React Native Firebase, which declares its own. Calling from JavaScript (`onMessage`, `setBackgroundMessageHandler`) cannot show a push from a killed app reliably.
185
+ - **No app code.** Both components come from the library's manifest.
186
+
187
+ Limits:
188
+
189
+ - **Shown twice** if something else also displays PushPilot's data-only messages, such as your own `FirebaseMessagingService` calling the Android SDK's `handleMessage`. React Native Firebase does not display data-only messages, and expo-notifications displays them only when they have a `title` or `message` key, which PushPilot's do not.
190
+ - FCM can, rarely, deliver a message twice. Firebase's own service drops recent duplicates by message id; the wrapper's receiver does not.
191
+
192
+ ## Taps on Android and iOS
193
+
194
+ `setLinkHandler` and `setTapHandler` behave the same on both platforms:
195
+
196
+ - **Which taps:** a tap on the push itself, or on a button with a link. Those open the app. A dismissal or a button without a link does not, and is not reported.
197
+ - **Order:** for a tap with a link, `setTapHandler` gets `{ notificationId, data }` first, then `setLinkHandler` gets the link.
198
+ - **Once:** each tap reaches each handler once, also after a JavaScript reload or when the app comes back to the foreground.
199
+ - **The tap that launched a killed app** waits until `init` and then goes to the handlers set before `init`. A handler set after `init` gets only later taps.
200
+ - **Without a link handler** the link opens through the system.
201
+
202
+ What differs underneath:
203
+
204
+ - **Android, without a link handler:** the SDK opens the link directly. If it is a web link, the browser opens and your app does not, so `setTapHandler` is not called for that tap. With a link handler set, your launcher activity opens first, then the link goes to JavaScript.
205
+ - **Android, adding a link handler in an app update:** the startup provider installs the native link handler only if the previous JavaScript run had one. So on the very first cold start after the update, a tap's link opens in the system. Later taps reach your handler.
206
+ - **iOS** always opens the app for these taps. Without a link handler, iOS then opens the link.
207
+
208
+ The link handler and tap data come from the native SDKs' own APIs (`setLinkHandler` and `tappedNotification` on Android, `setLinkHandler` and `userInfo["data"]` on iOS).
209
+
210
+ ## Upgrading from 1.x
211
+
212
+ - **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
+ - **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
+ - **New:** `setLinkHandler` and `setTapHandler`, on both platforms ([Taps](#taps-on-android-and-ios)).
215
+ - Every other call is unchanged, including `init`'s `baseUrl`.
216
+
217
+ ## API
218
+
219
+ ```tsx
220
+ import PushPilot, {
221
+ type AttributeValue,
222
+ type InitOptions,
223
+ type TappedNotification,
224
+ } from '@pushpilotai/react-native';
225
+ ```
226
+
227
+ | Call | What it does |
228
+ |---|---|
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. |
230
+ | `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
+ | `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
+ | `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. |
233
+ | `setTopics(list)` | Replaces the topic list (at most 100; letters, digits and `-_.~%`). Invalid names are dropped. |
234
+ | `logout()` | Clears the external user id. The device stays registered and keeps receiving pushes. |
235
+ | `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
+ | `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
+ | `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). |
238
+ | `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
+
240
+ Native, for the iOS `AppDelegate` (`import PushPilotReactNative`):
241
+
242
+ | Call | What it does |
243
+ |---|---|
244
+ | `RNPushPilotBridge.setDeviceToken(_ deviceToken: Data)` | Passes the APNs device token from `didRegisterForRemoteNotificationsWithDeviceToken`. |
245
+ | `RNPushPilotBridge.handleNotificationResponse(_ response) -> Bool` | Only when your own `UNUserNotificationCenter` delegate replaces the wrapper's after launch: call it from that delegate's `didReceive`. It records the click and feeds `setLinkHandler` and `setTapHandler`. `false` for pushes that are not from PushPilot. |
246
+
247
+ Invalid values are dropped by the native SDK with a log message instead of being sent. Native logs appear under the `PushPilot` tag in Logcat and the `ai.pushpilot.sdk` subsystem in the iOS console; the SDK key and push token are never logged.
248
+
249
+ ## What is sent, and store declarations
250
+
251
+ The data each sync carries, the `delivered` (Android) and `clicked` (both) events, when requests are made, and what to declare in Google Play's Data safety form and App Store Connect's App Privacy section are the same as for the native SDKs. The wrapper sends nothing of its own. See the [Android SDK README](https://github.com/pushpilotai/pushpilot-android#what-the-sdk-sends-and-when) and the [iOS SDK README](https://github.com/pushpilotai/pushpilot-ios#what-the-sdk-sends-and-when).
252
+
253
+ ## Example app
254
+
255
+ `example/`:
256
+
257
+ - 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
+ - **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
+ - **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.
260
+ - Buttons for set user id, set topics, logout and forget.
261
+
262
+ ```bash
263
+ yarn
264
+ yarn example start # Metro
265
+ yarn example android # or: yarn example ios
266
+ ```
267
+
268
+ It builds and runs without any Firebase config; Android then has no push identifier. To receive real pushes:
269
+
270
+ - Put your SDK key in `PUSHPILOT_SDK_KEY` in `example/src/App.tsx`.
271
+ - 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 and bundle ids you own on both targets, and give PushPilot the matching APNs key. The extension's bundle id must start with the app's.
273
+
274
+ On the iOS simulator you can try taps without a server:
275
+
276
+ ```bash
277
+ xcrun simctl push booted pushpilot.reactnative.example push.json
278
+ ```
279
+
280
+ Here `push.json` is `{"aps":{"alert":{"title":"Hi","body":"Tap me"}},"source":"pushpilot","notification_id":"<any uuid>","url":"https://example.com","data":{"order_id":"42"}}`. Tapping it, even with the app killed, records a click and reports the tap and then the link; the screen shows the link, the last of the two. Use a new `notification_id` for each try: each one is reported once per app process. `simctl push` does not run the extension, so image and buttons need a real push.
281
+
282
+ ## Local development
283
+
284
+ This repo and its example use the published native SDKs: `ai.pushpilot:sdk` from Maven Central and `https://github.com/pushpilotai/pushpilot-ios` from its tags. To work against unreleased changes in the native SDKs, check them out beside this repo:
285
+
286
+ ```
287
+ pushpilot-sdks/
288
+ pushpilot-android/
289
+ pushpilot-ios/
290
+ pushpilot-react-native/
291
+ ```
292
+
293
+ and switch these three places locally (don't commit them):
294
+
295
+ 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
+ 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 Extension:** in Xcode, replace the `pushpilot-ios` package under *Package Dependencies* with *Add Local…* and the checkout.
298
+
299
+ ### Checks
300
+
301
+ ```bash
302
+ yarn typecheck
303
+ yarn lint
304
+ yarn test # Jest: the JavaScript layer, with the native module mocked
305
+ yarn test:ios # the iOS APNs-hex parser, compiled with swiftc (macOS)
306
+ cd example/android && ./gradlew :pushpilot_react-native:testDebugUnitTest # the Android receiver's data filter
307
+ ```
308
+
309
+ ## Releasing
310
+
311
+ See [RELEASING.md](RELEASING.md) and [CHANGELOG.md](CHANGELOG.md).
312
+
313
+ ## Licence
314
+
315
+ Apache License 2.0. See [LICENSE](LICENSE).
@@ -0,0 +1,38 @@
1
+ ext.PushPilotReactNative = [
2
+ minSdkVersion: 24,
3
+ compileSdkVersion: 36
4
+ ]
5
+
6
+ ext.getExtOrDefault = { prop ->
7
+ if (rootProject.ext.has(prop)) {
8
+ return rootProject.ext.get(prop)
9
+ }
10
+
11
+ return PushPilotReactNative[prop]
12
+ }
13
+
14
+
15
+ apply plugin: "com.android.library"
16
+
17
+ if (project.extensions.findByName("kotlin") == null) {
18
+ apply plugin: "kotlin-android"
19
+ }
20
+
21
+
22
+ apply plugin: "com.facebook.react"
23
+
24
+ android {
25
+ namespace "ai.pushpilot.reactnative"
26
+
27
+ compileSdkVersion getExtOrDefault("compileSdkVersion")
28
+
29
+ defaultConfig {
30
+ minSdkVersion getExtOrDefault("minSdkVersion")
31
+ }
32
+ }
33
+
34
+ dependencies {
35
+ implementation "com.facebook.react:react-android"
36
+ implementation "ai.pushpilot:sdk:2.0.0"
37
+ testImplementation "junit:junit:4.13.2"
38
+ }
@@ -0,0 +1,24 @@
1
+ <manifest xmlns:android="http://schemas.android.com/apk/res/android">
2
+
3
+ <application>
4
+ <!--
5
+ Gets every FCM message from Google Play services, as React Native Firebase's own receiver
6
+ does, so PushPilot pushes are shown even when the app is killed and no JavaScript runs.
7
+ Coexists with the app's own FirebaseMessagingService: both receive each message.
8
+ -->
9
+ <receiver
10
+ android:name=".PushPilotMessageReceiver"
11
+ android:exported="true"
12
+ android:permission="com.google.android.c2dm.permission.SEND">
13
+ <intent-filter>
14
+ <action android:name="com.google.android.c2dm.intent.RECEIVE" />
15
+ </intent-filter>
16
+ </receiver>
17
+
18
+ <!-- Installs the link handler at process start, before the SDK handles the tap that launched a killed app. -->
19
+ <provider
20
+ android:name=".PushPilotStartupProvider"
21
+ android:authorities="${applicationId}.pushpilot-startup"
22
+ android:exported="false" />
23
+ </application>
24
+ </manifest>