node_apns icon indicating copy to clipboard operation
node_apns copied to clipboard

Sending payload with just badge returns invalid

Open JNK opened this issue 10 years ago • 2 comments

When trying to send a push notification which should just clear the badge count (e.g. set it to 0) an error ("Invalid") is returned.

JNK avatar Mar 31 '16 15:03 JNK

Modifying the isValid method of Notification to be

Notification.prototype.isValid = function () {
    if (!this.device || !this.device.isValid()) return false;

    var normalized = this.normalizedPayload();
    if (Buffer.byteLength(JSON.stringify(normalized), this.encoding) > 256) return false;
    if (!normalized.aps.alert && !normalized.aps.sound && normalized.aps.badge === undefined) return false;

    return true;
};

allows a badge value of 0 but not undefined

JNK avatar Mar 31 '16 16:03 JNK

Hey @JNK Thanks for spotting this! Would you like to make a PR ?

Orion98MC avatar Mar 31 '16 20:03 Orion98MC