node-apn / node-apn

:calling: Apple Push Notification module for Node.js
MIT License
4.37k stars 681 forks source link

Silent push notification does not fire application(_:didReceiveRemoteNotification:fetchCompletionHandler:) when app is in the background #691

Open andredanner opened 3 years ago

andredanner commented 3 years ago

Hi all,

I think time has come to ask the community to help me out as I am trying back and force now for 2 days to send a silent push notification to my device.

I did the following:

... .. var apnConnection = new apn.Provider(options);

    console.log('instantiating new note..');
    var note = new apn.Notification();
    note.topic = "com.xxxxxxxxx.yyyyyyyy";
    note.contentAvailable = 1;
    note.pushType = "background";
    note.priority = 5;

    apnConnection.send(note,token ).then( result => {
            console.log(result);
          });

BTW: Sending notes to APNS and Device works fine, as function is called as soon as my app gets in the foreground ..

kartsims commented 3 years ago

This may be related to #671

If the correct header is not passed then it may not be sent at all

FeleConvo commented 5 months ago

A lot of time has passed, but upgrading to 3.0.0 and setting Content Availabe as notification.aps["content-available"] = 1 instead of note.contentAvailable = 1 fixed it for me.

Reason being in the outgoing notification the content available is in camel case instead of separated by a dash.