【发布时间】:2019-07-21 05:37:21
【问题描述】:
我正在尝试使用 node.js 模块 firebase-admin 7.0.0 和以下代码向 iOS 设备发送静默数据通知:
// load lib
var firebase = require('firebase-admin');
// add API keys
firebase.initializeApp({
credential: firebase.credential.cert('./certs/firebase-private-key.json')
});
// device token send back from device
var token = '00397db1aa2f1fa625f71deef0c8e8ef0d4427cf60a13c0fb4bd290dcec41f4b';
// data message to send (contains no notification details so should be silent)
var message = {
data: {
key1: 'hello',
key2: 'world'
}
};
var options = {
priority: 'high',
timeToLive: 60 * 60 * 24,
contentAvailable: true,
mutableContent: true
};
// send the message
firebase.messaging().sendToDevice(token, message, options).then(function (res) {
// it worked!
console.log(res);
})
.catch(function (err) {
// it failed :(
console.log(err);
});
我收到一条回复说消息已发送,但它从未到达设备上。而如果我使用NWPusher 发送消息,它工作正常(下面的示例有效负载):
{"aps":{ "content-available": 1,"badge":0, "hello": "there" }}
有什么想法吗?
仅供参考:我还在GitHub开了一张票
【问题讨论】:
-
你检查了ios静默通知的payload吗
-
你是指 iOS 文档吗?
-
是的,我的意思是 ios 标准有效载荷,用于静默通知
-
只有静默通知不来。?还是正常的通知本身没有来..?
-
你能补充一下 sendToDevice 函数里面发生了什么
标签: ios firebase apple-push-notifications firebase-cloud-messaging