Skip to content

Commit 12207c5

Browse files
authored
fix(docs): ios foreground push notifications (#1587)
* fix: ios foreground notifications * fix: use the new data payload in the docs
1 parent d3e6770 commit 12207c5

File tree

2 files changed

+24
-4
lines changed

2 files changed

+24
-4
lines changed

docusaurus/docs/reactnative/guides/push_notifications_v2.mdx

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -279,10 +279,15 @@ messaging().setBackgroundMessageHandler(async remoteMessage => {
279279
});
280280

281281
// display the notification
282+
const { stream, ...rest } = remoteMessage.data ?? {};
283+
const data = {
284+
...rest,
285+
...((stream as unknown as Record<string, string> | undefined) ?? {}), // extract and merge stream object if present
286+
};
282287
await notifee.displayNotification({
283288
title: 'New message from ' + message.message.user.name,
284289
body: message.message.text,
285-
data: remoteMessage.data,
290+
data,
286291
android: {
287292
channelId,
288293
// add a press action to open the app on press
@@ -546,10 +551,15 @@ useEffect(() => {
546551
});
547552

548553
// display the notification
554+
const { stream, ...rest } = remoteMessage.data ?? {};
555+
const data = {
556+
...rest,
557+
...((stream as unknown as Record<string, string> | undefined) ?? {}), // extract and merge stream object if present
558+
};
549559
await notifee.displayNotification({
550560
title: 'New message from ' + message.message.user.name,
551561
body: message.message.text,
552-
data: remoteMessage.data,
562+
data,
553563
android: {
554564
channelId,
555565
pressAction: {

examples/SampleApp/src/hooks/useChatClient.ts

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,11 @@ messaging().setBackgroundMessageHandler(async (remoteMessage) => {
4545
});
4646

4747
if (message.message.user?.name && message.message.text) {
48+
const { stream, ...rest } = remoteMessage.data ?? {};
49+
const data = {
50+
...rest,
51+
...((stream as unknown as Record<string, string> | undefined) ?? {}), // extract and merge stream object if present
52+
};
4853
await notifee.displayNotification({
4954
android: {
5055
channelId,
@@ -53,7 +58,7 @@ messaging().setBackgroundMessageHandler(async (remoteMessage) => {
5358
},
5459
},
5560
body: message.message.text,
56-
data: remoteMessage.data,
61+
data,
5762
title: 'New message from ' + message.message.user.name,
5863
});
5964
}
@@ -111,6 +116,11 @@ export const useChatClient = () => {
111116
name: 'Foreground Messages',
112117
});
113118
// display the notification on foreground
119+
const { stream, ...rest } = remoteMessage.data ?? {};
120+
const data = {
121+
...rest,
122+
...((stream as unknown as Record<string, string> | undefined) ?? {}), // extract and merge stream object if present
123+
};
114124
await notifee.displayNotification({
115125
android: {
116126
channelId,
@@ -119,7 +129,7 @@ export const useChatClient = () => {
119129
},
120130
},
121131
body: message.message.text,
122-
data: remoteMessage.data,
132+
data,
123133
title: 'New message from ' + message.message.user.name,
124134
});
125135
}

0 commit comments

Comments
 (0)