我使用 Firebase Cloud Functions 通过 Cloud Messaging 向 iOS 设备发送通知。sendToDevice方法运行良好并返回成功承诺,Firebase Functions 日志中没有任何错误或警告,但在 iOS 上,不显示通知。如果我从 Firebase 通知仪表板发送通知,它运行良好,并且设备上会显示通知。我不知道我在哪里可以有错误。即使它像我说的那样工作,错误也可能在 iOS 应用程序端?
火力基地配置:
var functions = require('firebase-functions');
var admin = require('firebase-admin');
var config = functions.config();
admin.initializeApp(functions.config().firebase);
Run Code Online (Sandbox Code Playgroud)
部分云功能:
APP.services.firebase.admin.database().ref('tokens/' + userId).once('value', function(snapshot) {
var userDevicesTokens = [];
snapshot.forEach(function(childSnapshot) {
userDevicesTokens.push(childSnapshot.key)
});
if (userDevicesTokens.length === 0) {
console.warn('No tokens for user');
return;
}
var payload = {
data: {
title: options.title,
text: options.text,
type: options.type,
}
};
APP.services.firebase.admin.messaging().sendToDevice(userDevicesTokens, payload)
.then(function(response) {
console.log("Successfully sent message:", …Run Code Online (Sandbox Code Playgroud) javascript node.js firebase google-cloud-functions firebase-cloud-messaging