[FR] Issue with sendMulticast of admin SDK for FCM.
See original GitHub issueAre you in the right place?
Looks like I have run into some sort of bug with the Admin SDK. I am using Firebase Cloud Messaging to send Push Notification to iOS device. I am using the Admin SDK to send the message.
Describe your environment
- Operating System version: macOS Catalina 10.15.5
- Firebase SDK version: Firebase CLI (8.6.0) and Firebase Admin SDK (8.10.0)
- Firebase Product: Firestore/FCM/Firebase Admin SDK
- Node.js version: 14.5.0 and Node Engine 10
- NPM version: 6.14.5
Describe the problem
I am sending Push Notification (silent). I am using sendMulticast(message)
of Admin SDK.
It works fine with the following Message Payload:
const message = {
data: {
id: userId
},
tokens: deviceTokens
}
deviceTokens is an array of tokens. But this is payload for Android and it works for Android devices.
I also need to send Silent Push Notification to iOS. So I changed my payload to:
const message = {
data: {
id: userId
},
apns: {
headers: {
"apns-priority": "5",
"apns-push-type": "background"
},
payload: {
aps: {
"content-available": "1",
"data": {
"id": userId
}
}
}
},
tokens: deviceTokens
}
Here, this fails with an error: Error: Exactly one of topic, token or condition is required at FirebaseMessagingError.FirebaseError [as constructor]
It fails when I add the apns
dictionary.
I’ve been through the documentation and everything else, even through the admin.messaging.MulticastMessage
source code and the interfaces for MulticastMessage and I’m not doing anything wrong (looks like it).
Issue Analytics
- State:
- Created 3 years ago
- Comments:6 (2 by maintainers)
One possibility is your
deviceTokens
array containing some incorrect values. I was only able to reproduce the above error when my tokens array containednull
, empty string, or some other invalid item.One additional thing, and I just tested it right now, if I send the empty string without using the ‘apns’ key, then I don’t get the error.
const message = { data: { id: userId }, tokens: deviceTokens }
^ This doesn’t give an error if
deviceTokens
contains “” empty string. But with ‘apns’ key added, it does fail. That seems kinda funky and something you might want to check out @hiranya911