react-native - react-native-push-notification 前台通知
问题描述
我正在通过本机反应开发应用程序。
我需要发送一些带有推送通知的数据,但是在 android 中,当我收到通知时它会显示在屏幕上。
我配置了如下通知:
PushNotification.configure({
onRegister: function(token) {
Fetcher("userSetNotifToken",{notifToken:token.token},true);
},
onNotification: function(notification) {
console.log(notification);
if(platform == 'ios') {
if (notification.alert.extra !== undefined && notification.alert.extra.type == 'trip') {
alert("sad");
}
notification.finish(PushNotificationIOS.FetchResult.NoData);
}else{
if (notification.data !== undefined && notification.data.type == 'trip') {
Actions.reset("home", {trip: notification.data.trip});
}
}
},
senderID: "----",
permissions: {alert: true, badge: true, sound: true},
popInitialNotification: false,
requestPermissions: true,
});
有什么办法可以禁用这个选项?
解决方案
我在 react-native-push-notification 文件夹下的 node_modules 文件夹中找到了解决方案:
java/com/dieam/reactnativepushnotification/modules/RNPushNotificationListenerService.java
我改变了这个:
pushNotificationHelper.sendToNotificationCentre(bundle);
对此:
if (!isForeground) {
pushNotificationHelper.sendToNotificationCentre(bundle);
}
推荐阅读
- r - `mstate`:将“long”格式数据准备成“mstate”格式数据
- javascript - 如何在图表中显示数据?
- java - 如何在 web.xml 中创建多个通配符 url 模式?
- html - 如何从该网站获取 href attr?
- db2 - 在 DB2 SQL 函数中,是否有等效于 JAVA 和 .Net.. 中的 finally 块?
- javascript - 将所有数组对象(firestore 时间戳)转换为日期
- python - 从 Pandas 列中提取嵌套字典
- javascript - Javascript 函数仅在其他 javascript 函数被禁用时才有效
- perforce - 当我从工作区手动删除大量冗余文件时,如何将本地文件夹与仓库同步(提交),
- sql-server - 当排序顺序必须是特定于文化的时,如何支持分页?