【发布时间】:2017-10-04 15:29:10
【问题描述】:
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;
}
});
【问题讨论】:
-
你上传 p12 到 firebase 云消息部分了吗?
-
您好,感谢您的回复!我不太确定p12是什么? @JigneshMayani
-
您是否收到响应错误?
-
第一个 APNS 有 2 个证书 1 用于开发(如果您通过 ipa,则直接在设备上编译)或分发(如果您使用 testflight 或 appStore)在 fire base 您必须指定开发或生产并选择证书.由开发签名的应用获得证书开发的令牌(不适用于分发),反之亦然。
-
我用一张关于@AL 日志的图片更新了问题。
标签: ios node.js push-notification firebase-cloud-messaging google-cloud-functions