APNS functionality is supported by APN providers, but it is not compatible with NodeJS in a production

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.

Answer №1

When transitioning to production, I encountered a problem where the system was not functioning properly. In an attempt to resolve this issue, I decided to generate a new .p8 key. Although this initially seemed to solve the problem, it was later discovered that I had only updated the reference to the .p8 key and not the actual key parameter to match the one associated with my developer account. Once I corrected this oversight by updating the key parameter accordingly, all of my obstacles were successfully overcome.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

A helpful guide on performing a service call in AngularJs when attempting to close the browser tab or window

I am currently working on implementing a service call that will trigger when the browser tab or window is being closed. I was wondering if there is a way to make a RestApi call when attempting to close the browser tab or window. Does anyone have any sugge ...

Error message stating: "A missing module (MODULE_NOT_FOUND) was detected in the nest.js code

Having a code base that runs smoothly on a Windows machine using node v10.16.3, I encountered an issue when trying to install the same code on a CentOS Linux box with node v12.16.3. The error message displayed is regarding a missing module '@angular-d ...

Guide on converting the <br> tag within a string to an HTML tag in VUE.js

When working with Vue.js, I often use {{}} to display my data on the HTML page. However, I recently encountered a situation where my data includes a string with tags that I would like to be rendered as actual HTML tags when displayed. data(){ return ...

Tips for utilizing the beforeEach feature in node-tap?

Could someone please demonstrate how to utilize the beforeEach function? For more information, visit: . I am particularly interested in seeing an example using promises, although a callback version would also be appreciated. Below is a successfully functi ...

Eliminate items/attributes that include a certain term

Is there a way in Node.js to remove all fields or objects from a JSON file that have a specific word (e.g. "test") as their name, and then return the modified JSON file? Take a look at an example of the JSON file: { "name": "name1", "version": "0 ...

Implementing ajax functionality for a form component in vuejs

I am currently working with a Vue.js component that serves as a form with a single field for an email input. The default value of this field, "email", is provided to the component by the parent as a prop. Upon form submission, I need to trigger an event to ...

I'm looking for assistance on how to set the minimum height using jQuery. Can anyone provide

My attempt to use the minHeight property in one of my divs is not successful, and I am unsure why... <div id="countries"> <div class="fixed"> <div class="country" style="marging-left:0px;"></div> <div class="country"&g ...

Having trouble importing .env file into pm2 configuration - encountering an error

No matter how many online examples I follow, I can't seem to get my pm2 config to properly load my Node server. The recurring error message I keep encountering is: Error: Cannot find module 'dotenv/config'. My .env file is stored separately ...

Tips for utilizing an npm package in conjunction with Hugo

I created a basic hugo site with the following command: hugo new site quickstart Within the layouts/_default/baseof.html file, I have included a JavaScript file named script.js. Inside script.js, the code looks like this: import $ from 'jquery' ...

What is the best way to create a more compact Select component in React?

Working on React's Select component has been quite the challenge for me. I'm in the process of creating a simple dropdown button, also known as a ComboBox, similar to what can be seen on GitHub Insights: https://i.stack.imgur.com/J9Bcd.png Belo ...

What are some strategies for extracting additional information from a JSON file that spans multiple pages?

I am trying to figure out how to display a list of all characters when using a search bar. Currently, I can filter characters but the JSON data has multiple pages which limits the number of characters displayed. I have implemented logic to move to the next ...

development of MapLayers with rails and javascript

As a newcomer to RoR, I am encountering an issue that seems to be eluding me. I attempted to replicate the example application found on the mapLayers GitHub repository at https://github.com/pka/map_layers/wiki. However, all I see is the JavaScript code gen ...

Disappearing modal in Bootstrap 5 does not eliminate the backdrop

When using Bootstrap 5, I create my modal like this: var myModal = new bootstrap.Modal(document.getElementById('scheduleMeetingModal'), { backdrop: 'static' }); myModal.show(); Later on, when I want to hide the modal in another fun ...

Tips for choosing a particular list item using jQuery: retrieve the attribute value of 'value' and showcase it on the webpage

I have a task that requires the following: Implement an event listener so that when you click on any list item, the value of its "value" attribute will be shown next to this line. In my HTML, I have an ordered list with 8 list items. The values range fro ...

Generate a series of inquiries from an API response and display them dynamically, complete with a text field and radio button for each question

Currently, I am in the process of developing a Question/Answer page using ReactJS. The questions are retrieved through an API call. I aim to present a series of radio buttons and text fields for users to respond to these questions. A "Panel" that resemble ...

What could be causing ng-repeat to malfunction?

My ng-repeat is not working with the table - only the header part is being displayed in the output. I have checked my binding and it seems to be correct, but I know I am missing something. Can someone please help me figure out what I am doing wrong? JAVA ...

Utilize Postman to send a JSON body in a POST request to trigger a stored procedure on Microsoft SQL Server

I need to send a JSON request using the Postman app, utilizing the POST method to retrieve data. My boss, who is overseeing my training, assigned me this task. I've scoured the web for a week but haven't found a solution yet. Initially, I sugges ...

Establishing a connection between a Google spreadsheet to create and automatically update calendar events

I'm currently working on connecting my Google Sheet to a calendar so that it can automatically generate calendar events and keep them updated based on changes made in the sheet. The Google Sheet I'm using tracks new building opening dates and con ...

Unlimited scrolling: Fetching additional data via an Ajax request?

I am working on setting up a table with infinite scroll functionality to showcase user information such as name, address, and email. To accomplish this, I began by importing the json-server package and creating an API endpoint using fakerjs in a separate f ...

How can objects within an array be modified by adding foreign fields based on the value of another object?

Let's say I have a unique set of sectors: [ { sector: "IT", organizations: [ { org: "ACME", owners: [ "Josh", &q ...