Reputation: 321
I am trying to attach an image to my Firebase Push notification that is being sent to an iOS device. The iOS app is setup to accept notifications via Notification Service Extension for APNS.
The issue is the way I am trying to setup the payload for the Firebase call to Admin.messaging().sendToDevice(). There's an options parameter in the sendToDevice() function that has a 'mutableConent : true' field and says in the docs that it's for APNs payloads. I don't know how to add the APNs payload properly...
Here is my node.js code:
const payload = {
notification: {
title: publisher.Username + " posted a new Mag!",
body: "",
},
data : {
"fcm_options": {
"image": magImage,
},
}
}
let options = {
mutableContent : true
}
return admin.messaging().sendToDevice(deviceTokens, payload, options)
Any help on how to setup the payload or any other solution to add images would be helpful!
Upvotes: 1
Views: 3493
Reputation: 321
I found a solution! The problem was I was using the legacy API function call:
sendToDevice(registrationToken: string | string[], payload: admin.messaging.MessagingPayload, options?: admin.messaging.MessagingOptions)
where I should of been using the HTTP v1 API function call which is:
sendMultiCast(message: admin.messaging.MulticastMessage, dryRun?: boolean)
or send() if you're only send one notification to one user.
MulticastMessage inherits from 'BaseMessage' which includes all the criteria for sending FCM push notifications with images and rich notification options
(fcm_options
for Apple Push Notifications).
Upvotes: 2