Configure the notification payload
masterYou can define the JSON payload sent to the device using two different approaches:
notification.payload: An object that is JSON encoded. When you set properties onnotification.aps(via convenience setters), they are merged into this payload just before transmission. Ifpayloadalready contains anapsproperty, it is replaced by theapsproperties set via the notification object.notification.rawPayload: If provided, this object is encoded and transmitted exactly as-is. UsingrawPayloadmeans convenience setters (like.bodyor.title) will have no effect on the final JSON output.
// Using .payload (merges with aps properties)
let notification = new apn.Notification();
notification.payload = {
from: "node-apn",
source: "web",
};
notification.body = "Hello, world!";
// Using .rawPayload (overrides everything, ignores setters)
let notificationRaw = new apn.Notification();
notificationRaw.rawPayload = {
from: "node-apn",
source: "web",
aps: {
"content-available": 1
}
};
notificationRaw.body = "Hello, world!"; // This will be ignored in the output