node-apn / node-apn

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

Push notification is not working on https #705

Open GitanjaliCS opened 2 years ago

GitanjaliCS commented 2 years ago

Hello,

I am working on PWA app. and I am trying to send push notification to ios app. Notification is working when i am sending notification from local PWA app

and notification is not working if PWA app is on https.

Please help me, i am trying from 2 days.

Below is my code

var apn = require('apn');

var options = {
  token: {
    key: `${appRoot}/AuthKey_TQ396UWXAC.p8`,
    keyId: "TQ396UWXAC",
    teamId: "QB328QX9RD"
  },
  production: true
};
let apnCustomerConnection = new apn.Provider(apnoptions);
apnCustomerConnection.on("transmissionError", function(errCode, notification, device) {
console.log('apnError',"customer transmission Error");
});
apnCustomerConnection.on("timeout", function () {
    console.log('apnError',"customer Connection Timeout");
});
apnCustomerConnection.on("disconnected", function() {
    console.log('apnError',"customer Disconnected from APNS");
});
apnCustomerConnection.on("socketError", function(err){
    console.log('apnError',"customer socketError",err);    
});

 var apnProvider = new apn.Provider(options);

  var note = new apn.Notification();

  note.expiry = Math.floor(Date.now() / 1000) + 3600; // Expires 1 hour from now.
  note.alert = req.body.message;
  note.topic = "com.cskills.abbeyschool";

  note.payload = {'request_details': item, 'message': req.body.message};
  let deviceToken = DEVICE TOKEN;

  apnProvider.send(note, deviceToken).then( (result) => {                      
    res.send(result);
  });

Thank you in advance.