I've set up a nodeJS script to send APNs. In development, it always works flawlessly. However, when I switch to production, the notifications never go through. Oddly enough, when I use the same notification ID with my production certificate in Easy Apn Provider, it goes through without any issues. I'm puzzled as to why this could be happening. If there was an issue with my profile or certificates, wouldn't the Easy Apn also fail?
https://i.stack.imgur.com/39EHN.png
APN Configuration
var options = {
token: {
cert: "certificate.pem",
pfx: "Certificate.p12",
key: "AuthKey_XCVK62CSQF.p8",
keyId: "3Z6SEF7GE5",
teamId: "ASQJ3L7765"
},
production: true,
gateway: 'gateway.push.apple.com', // gateway address
port: 2195
};
var apnProvider = new apn.Provider(options);
Result:
//IOS notification function
function SendIOSNotification(token, message, sound, payload, badge){
var deviceToken = token; //device's notification ID
var notification = new apn.Notification(); //prepare notification
notification.topic = 'com.GL.Greek-Life'; // Specify your iOS app's Bundle ID
notification.expiry = Math.floor(Date.now() / 1000) + 3600;
notification.badge = badge;
notification.sound = sound;
notification.alert = message;
notification.payload = {id: payload};
apnProvider.send(notification, deviceToken).then(function(result) {
var subToken = token.substring(0, 6);
console.log("Message sent successfully to ", subToken);
}).catch( function (error) {
console.log("Failed to send message to ", subToken);
})
}
The message was successfully sent to 5D..
Edit: While analyzing the response, I discovered that the notification failed with a 403 error (ID doesn't exist), although it worked fine with Easy Apn. I suspect the issue might be related to generating a non-production ID, but I don't understand how that's happening. My build has been signed and uploaded on Testflight, and all traces of development profiles have been removed, leaving only production profiles and certificates. I'm unsure why this discrepancy exists.