This is what my log looks like when my push notification gets called on火力地堡雲消息推送通知送交設備
我目前正在創建推送通知設置爲用戶用戶設置的iPhone。我目前正在使用Firebase,所以很自然地轉向使用Firebase Cloud Messaging來完成此項任務。這是我部署到我的Firebase的功能中的設置。有沒有什麼我在這裏做錯了會導致通知沒有被髮送到設備?我感謝任何幫助,如果有更多所需的信息,我會很樂意提供。
const functions = require('firebase-functions');
const admin = require('firebase-admin');
admin.initializeApp(functions.config().firebase);
// Listens for new messages added to messages/:pushId
exports.pushNotification = functions.database.ref('/messages/{pushId}').onWrite(event => {
console.log('Push notification event triggered');
// Grab the current value of what was written to the Realtime Database.
var valueObject = event.data.val();
console.log(valueObject)
if(valueObject.photoUrl != null) {
valueObject.photoUrl= "Sent you a photo!";
}
// Create a notification
const payload = {
notification: {
title:valueObject.toId,
body: valueObject.text || valueObject.photoUrl,
sound: "default"
},
};
//Create an options object that contains the time to live for the notification and the priority
const options = {
priority: "high",
timeToLive: 60 * 60 * 24
};
return admin.messaging().sendToTopic("pushNotifications", payload, options);
if(!data.changed()){
});
exports.pushNotification = functions.database.ref('/messages/{pushId}').onWrite(event => {
const data = event.data;
console.log('Push notification event triggered');
return;
}
});
你上傳了firebase雲消息部分的p12嗎? –
嘿謝謝你的回覆!我不太確定p12是什麼? @JigneshMayani – oneQuestionAsker
您是否在迴應中發生錯誤? –