基本上情况是我收到一条(仅数据)远程消息,然后推送本地通知并向其添加操作,但是当涉及到在后台处理它们并退出状态时,我单击操作没有任何反应,这是我的代码调用我的index.js
PushNotification.configure({
onNotification: function (notification) {
const appState = AppState.currentState;
if (appState !== 'active') {
if (!notification.userInteraction) {
PushNotification.localNotification({
channelId: '// some chennel id',
title: notification.data.title,
message: notification.data.message,
priority: 'high',
actions: JSON.parse(notification.data.actions).map(
(item: any) => item.title,
),
smallIcon: 'ic_notification_icon',
largeIcon: '',
bigText: '',
subText: '',
bigPictureUrl: '',
userInfo: notification.data,
});
} else {
const actionIdentifier = notification.action;
if (!actionIdentifier) return;
switch (actionIdentifier) {
case 'YES':
console.log('YEEEEES');
break;
case 'NO':
console.log('NOOOOP');
break;
case 'CHECK':
console.log('check it')
// this action should open the app and navigate to a notifs screen
break;
default:
console.log('No actionIdentifier selected', actionIdentifier);
break;
}
}
}
},
});
when i receive the notification here's what notification param logs
{
"foreground": false,
"subText": "",
"smallIcon": "ic_notification_icon",
"priority": "high",
"actions": "[\"YES\",\"NO\",\"CHECK\"]",
"userInteraction": true,
"bigText": "",
"id": "1187834229",
"category": "userAction",
"title": "test",
"largeIcon": "",
"message": "test test test",
"channelId": "// some channel id",
"bigPictureUrl": "",
"data": {}
}
嗯,尝试了我在互联网上找到的所有内容,但没有任何效果
使用 userInfo 作为对象似乎对我来说在通过通知传递附加数据方面效果很好。
PushNotification.localNotificationSchedule({
channelId: channelId,
date: notification.date,
title: notification.title,
subText: notification.subTitle,
message: notification.message,
showWhen: false,
bigPictureUrl: notification.image,
repeatType: notification.repeatType,
picture: notification.image,
repeatTime: notification.repeatTime,
priority: 'max',
importance: 'max',
allowWhileIdle: true,
when: notification.date.getTime(),
userInfo: {
path: notification.navigate,
channel: notification.id,
data: notification.item,
},
vibrate: true,
vibration: 300,
});