When we are sending a FCM data message with the Firebase Admin SDK to an iOS device we are getting the following exception.
com.google.firebase.messaging.FirebaseMessagingException: Request contains an invalid argument.
We are using com.google.firebase:firebase-admin:6.7.0
and the message is build like this.
Message.builder()
.setApnsConfig(ApnsConfig.builder()
.putHeader("apns-priority", "10")
.setAps(Aps.builder()
.setContentAvailable(true)
.build())
.build())
.putAllData(data)
.setToken(token)
.build();
I don't think that there is something wrong with the token itself, because sending a push notification to this token works.
Also the message size shouldn't be an issue, because it is basically just an id in it.
I'm not sure if it happens on all iOS devices. Am i missing something on building the data message?
Update
I checked the details included at the exception and there it looks like something is wrong with the token.
{
"error": {
"code": 400,
"message": "Request contains an invalid argument.",
"status": "INVALID_ARGUMENT",
"details": [
{
"@type": "type.googleapis.com/google.firebase.fcm.v1.FcmError",
"errorCode": "INVALID_ARGUMENT"
},
{
"@type": "type.googleapis.com/google.rpc.BadRequest",
"fieldViolations": [
{
"field": "message.token",
"description": "Invalid registration token"
}
]
}
]
}
}
But when i send a data message to the same token using postman, there is no error and the response looks like this.
{
"multicast_id": 7455611938954436367,
"success": 1,
"failure": 0,
"canonical_ids": 0,
"results": [
{
"message_id": "0:1614145427166557%c5757de0f9fd7ecd"
}
]
}
I think i figured it out.
My problem was that i was setting the apns-priority
to "10". According to the documentation, notifications with a priority of "10" have to be delivered immediatly.
If i put my device into flight mode for example, and sending my data push it failes with the mentioned firebase exception about an invalid token. Which is very missleading in my opinion.
If i set the apns-priority
to "5" everything works fine.