【发布时间】:2019-12-01 07:45:24
【问题描述】:
假设我们想像这样向两个registrationTokens(只有Android设备,没有iOS)发送一个通知:
const tokens = ['tokenA', 'tokenB'];
const payload = {badge: 1, title: 'Hello', body: 'world'};
const options = {priority: 'high',contentAvailable: false, timeToLive: 60 * 60 * 24};
const admin = FirebaseAdmin.initializeApp({/*config here...*/});
admin.messaging().sendToDevice(deviceTokens, payload, options)
.then((response) => {
response.results.forEach((deviceResult) => {
if (deviceResult.error) {
console.log('Delivery failed. Showing result:\n', deviceResult);
}
});
});
曾经在tokenB 注册过设备的用户从他的设备中删除了该应用。因此,该令牌不再向 Firebase 注册。
错误对象如下所示:
Delivery failed. Showing result:
{"error":
{
"code":"messaging/registration-token-not-registered",
"message":"The provided registration token is not registered. A previously valid registration token can be unregistered for a variety of reasons. See the error documentation for more details. Remove this registration token and stop using it to send messages."
}
}
问题: 我的问题是,我只知道其中一个交付失败。但我不知道错误与哪个令牌有关。因此我无法从数据库中删除过时的令牌。
问题: 有没有办法找出交付失败的代币?
Github 问题链接:https://github.com/firebase/firebase-admin-node/issues/600
【问题讨论】:
-
仅供参考:我已经创建了一个关于该主题的 GitHub 问题:github.com/firebase/firebase-admin-node/issues/600
标签: node.js push-notification firebase-admin