【发布时间】:2020-12-04 14:05:33
【问题描述】:
推送通知功能:
PushNotification.configure({
largeIcon: "ic_launcher",
smallIcon: "ic_notification",
onNotification: function (notification) {
PushNotification.localNotification({
autoCancel: true,
message: 'Test Message',
title: 'Test Message',
vibrate: true,
vibration: 300,
playSound: true,
soundName: 'default'
})
console.log(notification)
},
});
问题:
- 当我运行应用程序时,如果我从 php 服务器发送通知,我会在 console.log 中得到响应
但是
条件 1:PushNotification.localNotification() 前台不工作。
条件 2:PushNotification.localNotification() 后台不工作。
- 如果我从 firebase 服务器发送通知,我会在 console.log 中得到响应
但是
条件 3:PushNotification.localNotification() 前台不工作。
条件 4:PushNotification.localNotification() 后台工作。
在我收到来自 firebase 服务器的第一个通知后,即条件 4,我的应用程序也开始接收来自上述所有其他 3 个条件的通知。奇怪但我测试了很多次
- 如果我点击通知,那么通知在栏中仍然可见
- 在 OnePlus9 设备上,整体通知不起作用。
我收到了来自 php 服务器的响应:
{
"data":
{
"message": "Your order with order no OID63112 has been dispatched. Expected time for arrival is 30 min",
"title": "Picked up order",
"vibrate": "1"
},
"from": "326331584681",
"messageId": "0:1607089521078208%d58aa421f9fd7ecd",
"sentTime": 1607089521064,
"ttl": 2419200
}
我收到来自 firebase 服务器的响应:
{
"channelId": "fcm_fallback_notification_channel",
"color": null,
"data": {},
"finish": [Function finish],
"foreground": true, "id": "-1787502606",
"message": "Enjoy your meat! Order Online!",
"priority": "high",
"sound": null,
"tag": "campaign_collapse_key_4040075812614528488",
"title": "Freshcut",
"userInteraction": false,
"visibility": "private"
}
我的配置是
"@react-native-firebase/app": "^8.4.7",
"@react-native-firebase/crashlytics": "^8.4.9",
"@react-native-firebase/database": "^10.0.0",
"@react-native-firebase/messaging": "^7.9.0",
"react-native-push-notification": "^6.1.3",
android/build.gradle
ext {
buildToolsVersion = "29.0.2"
minSdkVersion = 19
compileSdkVersion = 29
targetSdkVersion = 29
googlePlayServicesVersion = "+" // default: "+"
firebaseMessagingVersion = "+" // default: "+"
}
android/app/src/main/AndroidManifest.xml
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<permission
android:name="com.freshcut.permission.C2D_MESSAGE"
android:protectionLevel="signature" />
<uses-permission android:name="com.freshcut.permission.C2D_MESSAGE" />
<!-- Change the value to true to enable pop-up for in foreground (remote-only, for local use ignoreInForeground) -->
<meta-data android:name="com.dieam.reactnativepushnotification.notification_foreground"
android:value="false"/>
<!-- Change the resource name to your App's accent color - or any other color you want -->
<meta-data android:name="com.dieam.reactnativepushnotification.notification_color"
android:resource="@color/white"/> <!-- or @android:color/{name} to use a standard color -->
<receiver android:name="com.dieam.reactnativepushnotification.modules.RNPushNotificationActions" />
<receiver android:name="com.dieam.reactnativepushnotification.modules.RNPushNotificationPublisher" />
<receiver android:name="com.dieam.reactnativepushnotification.modules.RNPushNotificationBootEventReceiver">
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
<action android:name="android.intent.action.QUICKBOOT_POWERON" />
<action android:name="com.htc.intent.action.QUICKBOOT_POWERON"/>
</intent-filter>
</receiver>
<service
android:name="com.dieam.reactnativepushnotification.modules.RNPushNotificationListenerService"
android:exported="false" >
<intent-filter>
<action android:name="com.google.firebase.MESSAGING_EVENT" />
</intent-filter>
</service>
我无法找到确切的问题,我也阅读了所有其他问题并尝试了不同的解决方案,但没有任何结果。 我是 react-native-puch-notification 的新手。
【问题讨论】:
标签: firebase react-native firebase-cloud-messaging localnotification react-native-push-notification