Seb*_*ien 21 firebase firebase-cloud-messaging firebase-admin
我正在尝试使用以下代码通过 FCM 从 Firebase Cloud 函数发送多播通知:
const message = {
tokens: recipients,
notification: {
title: title,
body: body
},
data: {
projectPartnerId: projectPartnerId
}
};
return admin.messaging().sendMulticast(message);
Run Code Online (Sandbox Code Playgroud)
并且没有发送任何推送通知。每个响应都包含一个带有相同消息的错误:“未找到请求的实体”。
我在 Google Cloud 控制台中启用了 API(Firebase 文档中没有提到它,但显然这是必要的)。我不知道我还能做什么。我能找到的所有其他问题都与 HTTP API 或遗留 API 相关。我使用的是最新版本的 Firebase Admin SDK。
Seb*_*ien 25
弄清楚了。显然,当我尝试发送到的 FCM 令牌不再注册时,就会发生此错误,如"messaging/registration-token-not-registered"错误代码所示。在这种情况下,我只需要从用户的令牌中删除此令牌并完成它。
正如@user1123432所述,我只是做了如下操作:
try {
// Logic to send a push notification goes here
catch (e: Exception) {
logger.error("Firebase Notification Failed: ${e.message}")
if (e is FirebaseMessagingException) {
logger.info("Firebase Notification token for the user: ${user.userName}, errorCodeName: ${e.errorCode.name}, messagingErrorCodeName: ${e.messagingErrorCode.name}")
if (e.errorCode.name == "INVALID_ARGUMENT" || e.errorCode.name == "NOT_FOUND" || e.messagingErrorCode.name == "UNREGISTERED") {
myNotificationTokenRepo.clearTokenByUserId(user.uuid)
logger.info("Deleted Firebase Notification token for the user: ${user.userName}")
}
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
26105 次 |
| 最近记录: |