@attentive-mobile/attentive-react-native-sdk 2.0.0-beta.8 → 2.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +41 -28
- package/package.json +6 -2
package/README.md
CHANGED
|
@@ -109,6 +109,7 @@ class MainApplication : Application(), ReactApplication {
|
|
|
109
109
|
.applicationContext(this)
|
|
110
110
|
.domain("YOUR_ATTENTIVE_DOMAIN")
|
|
111
111
|
.mode(AttentiveConfig.Mode.PRODUCTION) // or Mode.DEBUG for testing
|
|
112
|
+
.notificationIconId(R.drawable.ic_stat_notification)
|
|
112
113
|
.skipFatigueOnCreatives(false)
|
|
113
114
|
.logLevel(AttentiveLogLevel.VERBOSE)
|
|
114
115
|
.build()
|
|
@@ -120,6 +121,30 @@ class MainApplication : Application(), ReactApplication {
|
|
|
120
121
|
}
|
|
121
122
|
```
|
|
122
123
|
|
|
124
|
+
##### Android notification small icon
|
|
125
|
+
|
|
126
|
+
Android requires push notifications to use a small status-bar icon. If `notificationIconId` is not set, the Attentive Android SDK uses its default fallback icon. To use your app's branding, add a notification small icon resource to your host app and pass its resource ID during native initialization.
|
|
127
|
+
|
|
128
|
+
Add the icon to your Android app's drawable resources:
|
|
129
|
+
|
|
130
|
+
```text
|
|
131
|
+
android/app/src/main/res/drawable/ic_stat_notification.png
|
|
132
|
+
```
|
|
133
|
+
|
|
134
|
+
Use a white-only transparent PNG designed for Android notification status bars. Do not use the full-color launcher icon from `mipmap-*`, because Android masks small notification icons and it can render poorly.
|
|
135
|
+
|
|
136
|
+
Then add the icon to your existing `AttentiveConfig.Builder()` chain in `MainApplication.kt` before `build()`:
|
|
137
|
+
|
|
138
|
+
```text
|
|
139
|
+
android/app/src/main/java/<your-package>/MainApplication.kt
|
|
140
|
+
```
|
|
141
|
+
|
|
142
|
+
```kotlin
|
|
143
|
+
.notificationIconId(R.drawable.ic_stat_notification)
|
|
144
|
+
```
|
|
145
|
+
|
|
146
|
+
`MainApplication.kt` is host-app code, not generated by this SDK at runtime. If `R.drawable.ic_stat_notification` does not resolve, confirm the drawable file name matches exactly and that you are referencing your app module's `R` class.
|
|
147
|
+
|
|
123
148
|
After the native initialization, all other SDK operations (`identify`, `recordAddToCartEvent`, `recordPurchaseEvent`, etc.) are called from TypeScript as normal on both platforms.
|
|
124
149
|
|
|
125
150
|
> **Tip:** If you see `[AttentiveSDK] recordAddToCartEvent failed — SDK may not be initialized` in your Android logcat, it means `AttentiveSdk.initialize()` was not called from native code before the event was recorded. Check your `Application.onCreate()` setup.
|
|
@@ -281,57 +306,45 @@ identify({ email: 'user@example.com', clientUserId: 'id-123' });
|
|
|
281
306
|
|
|
282
307
|
#### Push notifications on Android (FCM)
|
|
283
308
|
|
|
284
|
-
|
|
309
|
+
The Attentive Android SDK registers its own `FirebaseMessagingService` automatically — **you do not need to create a subclass**. As long as your app is registered with Firebase and includes a valid `google-services.json`, the SDK handles FCM token registration and foreground push delivery for you. Follow the [Firebase Android setup guide](https://firebase.google.com/docs/cloud-messaging/android/client) to add FCM to your project.
|
|
310
|
+
|
|
311
|
+
##### If you already have a FirebaseMessagingService subclass
|
|
285
312
|
|
|
286
|
-
|
|
313
|
+
If your app has an existing `FirebaseMessagingService` subclass for other purposes, route Attentive messages through to the SDK:
|
|
287
314
|
|
|
288
315
|
```kotlin
|
|
289
316
|
import com.attentive.androidsdk.AttentiveSdk
|
|
290
317
|
import com.google.firebase.messaging.FirebaseMessagingService
|
|
291
318
|
import com.google.firebase.messaging.RemoteMessage
|
|
292
319
|
|
|
293
|
-
class
|
|
294
|
-
|
|
295
|
-
override fun onNewToken(token: String) {
|
|
296
|
-
super.onNewToken(token)
|
|
297
|
-
// Register the FCM token with the Attentive SDK
|
|
298
|
-
AttentiveSdk.registerDeviceToken(token)
|
|
299
|
-
}
|
|
320
|
+
class YourFirebaseMessagingService : FirebaseMessagingService() {
|
|
300
321
|
|
|
301
322
|
override fun onMessageReceived(remoteMessage: RemoteMessage) {
|
|
302
323
|
super.onMessageReceived(remoteMessage)
|
|
303
|
-
|
|
304
|
-
|
|
324
|
+
if (AttentiveSdk.isAttentiveFirebaseMessage(remoteMessage)) {
|
|
325
|
+
AttentiveSdk.sendNotification(remoteMessage)
|
|
326
|
+
}
|
|
327
|
+
// Handle your own messages below...
|
|
305
328
|
}
|
|
306
329
|
}
|
|
307
330
|
```
|
|
308
331
|
|
|
309
|
-
|
|
332
|
+
##### Notification opens (singleTask apps)
|
|
333
|
+
|
|
334
|
+
React Native apps use `singleTask` launch mode by default. When a push notification is tapped while the app is in the background, Android delivers the intent via `onNewIntent()` rather than recreating the activity. Override `onNewIntent` in your `MainActivity` so the SDK can detect the notification tap:
|
|
310
335
|
|
|
311
336
|
```kotlin
|
|
312
|
-
import
|
|
337
|
+
import android.content.Intent
|
|
313
338
|
|
|
314
339
|
class MainActivity : ReactActivity() {
|
|
315
340
|
|
|
316
|
-
override fun
|
|
317
|
-
super.
|
|
318
|
-
intent?.let {
|
|
341
|
+
override fun onNewIntent(intent: Intent?) {
|
|
342
|
+
super.onNewIntent(intent)
|
|
343
|
+
intent?.let { setIntent(it) }
|
|
319
344
|
}
|
|
320
345
|
}
|
|
321
346
|
```
|
|
322
347
|
|
|
323
|
-
Declare the service in your `AndroidManifest.xml`:
|
|
324
|
-
|
|
325
|
-
```xml
|
|
326
|
-
<service
|
|
327
|
-
android:name=".AttentiveMessagingService"
|
|
328
|
-
android:exported="false">
|
|
329
|
-
<intent-filter>
|
|
330
|
-
<action android:name="com.google.firebase.MESSAGING_EVENT" />
|
|
331
|
-
</intent-filter>
|
|
332
|
-
</service>
|
|
333
|
-
```
|
|
334
|
-
|
|
335
348
|
Refer to the [Attentive Android SDK documentation](https://github.com/attentive-mobile/attentive-android-sdk) for the full list of native APIs available for push notification integration.
|
|
336
349
|
|
|
337
350
|
---
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@attentive-mobile/attentive-react-native-sdk",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.1",
|
|
4
4
|
"description": "React Native Module for the Attentive SDK",
|
|
5
5
|
"main": "lib/commonjs/index",
|
|
6
6
|
"module": "lib/module/index",
|
|
@@ -16,6 +16,10 @@
|
|
|
16
16
|
"*.podspec",
|
|
17
17
|
"!lib/typescript/example",
|
|
18
18
|
"!ios/build",
|
|
19
|
+
"!ios/Pods",
|
|
20
|
+
"!ios/Podfile.lock",
|
|
21
|
+
"!ios/*.xcworkspace",
|
|
22
|
+
"!**/xcuserdata",
|
|
19
23
|
"!android/build",
|
|
20
24
|
"!android/gradle",
|
|
21
25
|
"!android/gradlew",
|
|
@@ -111,7 +115,7 @@
|
|
|
111
115
|
"release-it": {
|
|
112
116
|
"git": {
|
|
113
117
|
"commitMessage": "chore: release ${version}",
|
|
114
|
-
"tagName": "
|
|
118
|
+
"tagName": "${version}"
|
|
115
119
|
},
|
|
116
120
|
"npm": {
|
|
117
121
|
"publish": true
|