我正在尝试将FCM通知集成到我的项目中。我有Cloud Function后台,应用程序运行在android上。以下是用于发送通知的云代码:
exports.notificationTest = functions.database.ref(`/test/childA/childB/status`).onUpdate(event => {
const status = event.data.val();
console.info("Processing notificationTest cloud function")
console.info(`status : ${status}`)
const token = "EnterYourNotificationTokenHere"
const randomNum = Math.floor(Math.random() * 100)
var message = {
notification: { title : "My App", body : `Notification Test ${randomNum}`}
}
console.info(`Sending message on notification token`)
return admin.messaging().sendToDevice(token, message)
.then((response) => {
console.info("Successfully sent notification")
}).catch(function(error) {
console.warn("Error sending notification " , error)
})
})在原生Android应用程序上,我多次收到通知,间隔几分钟。在这里,我看到了这样的通知:
Notification Test 30然后,在2、4、8、16、32分钟的前一次通知时间后,我再次收到以下消息
Notification Test 30我不认为我需要在这里粘贴日志,因为代码肯定只执行一次(因为通知中的随机数保持不变)。
那么,为什么会发生这种情况,以及如何修复它?
下面是我的环境:
Native Android App
Using Android 7
Latest Android Studio Stable
Android Gradle Plugin - 3.1.1
Gradle - 4.1
Firebase-Ui - 3.1.0
Play Services - 11.4.2请尝试在上面提到的环境中繁殖。
https://stackoverflow.com/questions/47429141
复制相似问题