【发布时间】:2018-01-01 20:11:49
【问题描述】:
现在我的有效负载只发送 1 个标记计数,标记计数的值不会增加。即使您收到超过 1 个通知,它仍保持为 1。
javascript应该怎么写?
我当前的代码:
const functions = require('firebase-functions');
const admin = require('firebase-admin');
admin.initializeApp(functions.config().firebase);
exports.sendPushForHelp =
functions.database.ref('/help/school/{id}').onWrite(event => {
const payLoad = {
notification: {
title: 'Someone',
body: 'needs help',
badge: '1',
sound: 'Intruder.mp3'
}
};
return admin.database().ref('fcmToken').once('value').then(allToken => {
if (allToken.val()) {
const token = Object.keys(allToken.val());
return admin.messaging().sendToDevice(token, payLoad).then(response => {
});
};
});
});
【问题讨论】:
-
你不能只做一个增量 int 并将 const payLoad 中的
badge值设置为等于那个值吗? -
您的意思是我应该在 xcode (swiftcode) 中包含增量 int。然后我应该在有效载荷中使用该变量。让我们说徽章:badgecount?
-
这可行,我什至建议将 var 存储在 JS 中
-
你能给我举个例子吗?我对 JS 很陌生。你应该在哪里声明变量?
-
确定我会在答案中快速写下
标签: javascript swift apple-push-notifications firebase-cloud-messaging google-cloud-functions