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

Update the color of navigation items to reflect their active status

Here is the snippet of HTML code: <header> <nav> <a href="#" id="menu-icon"></a> <ul> <li><a href="#"">Home</a></li> <li><a href="#">About</a></li> & ...

The server.js file is malfunctioning and unable to run

Here are the versions I am using in my application: "node": "7.2.1", "npm": "4.4.4" "@angular/cli": "1.4.9", "@angular/core": "4.4.6" After deploying my application on Heroku, it built successfully. However, when I try to run it, I encounter an "Applica ...

Error in Next.js: ReferenceError: document is not defined

Having trouble setting up a payment form for users to make payments, encountering the error message below: document is not defined Currently working with Next.js. Here is the code snippet I'm using: import React from "react"; import {Elem ...

``Are you looking to create multiple canvases in a loop?

I've managed to get this command working exactly as I wanted: http://jsfiddle.net/m1erickson/64BHx/ However, I didn't anticipate how challenging it would be to turn the drawing into reality here: What I attempted to do is illustrated in this li ...

Having trouble creating a unit test for exporting to CSV in Angular

Attempting to create a unit test case for the export-to-csv library within an Angular project. Encountering an error where generateCsv is not being called. Despite seeing the code executed in the coverage report, the function is not triggered. Below is the ...

Has anyone experienced a problem with Google OpenId where the redirect_uri/callback is not occurring? Could the problem possibly

As per the guidance provided in the Google OpenID documentation, I am currently trying to initiate an authentication request to Google. Upon sending the request to , the redirection back to my specified redirect_uri http://localhost:5901 is not happening. ...

Mobile devices are unable to properly implement the Jquery show/hide feature

Currently, I am working on a small Russian project and facing some challenges with the mobile version of my website: php8098.github.io/breakfast. The issue lies within the first slider where the play button should trigger a modal window to open. I urgentl ...

Handling an Express server that receives a request with no data

I'm struggling with a problem where I am unable to retrieve a basic JSON object. When I log it to the console, all I see is {}. Let me showcase the server code below: const express = require("express"); const app = express(); app.listen(3000); app.us ...

Encountering an issue with a Discord bot causing it to malfunction and deviate from its intended

Initially, everything appears to be functioning properly with the bot. When I execute the ?listen command, it responds correctly with bot is collecting messages now.... However, the ?stop command does not seem to have any effect. Furthermore, when I try th ...

Identifying differences in a Knockout view model

While it may seem like a simple question, is there actually a straightforward method to identify if there has been a change in any property of a knockout view model? ...

What is a clear indication that a <div> is filled with text?

Picture a scenario where a website contains an element that needs to be filled with random text using JavaScript. Once the div is completely filled, it should reset and begin again. It may sound odd, but the question is: how will the JavaScript determine w ...

Is it feasible to retrieve information within a behavior in Drupal?

I recently installed the "Autologout" Drupal module, which can be found at . This module includes a timer that ends your session if there is no activity on the page for a set period of time. However, I am interested in adjusting the timer value to better ...

Cutting Out Sections of a List

I'm currently working on an app that involves looking up and navigating to specific locations. I've encountered an issue with the coordinates in my code containing a ',0' at the end, which is not compatible with Google Maps. Manually re ...

The webpage isn't displaying the API response properly: the weather variable is not defined in Proxy.created

I have been utilizing AXIOS to fetch weather information from an API and showcase it dynamically on my Vue page. Initially, the API request goes through successfully and I am able to present the data on the page. However, when attempting to use v-for to ex ...

Stranger things happening when incorporating a generator function in React

Here's a simplified version of my component. It includes a generator function that cycles through values. const App = () => { const [state, setState] = useState("1") function* stateSwitch () { while (true){ yield "2" yield "3" ...

Why won't my setTimeout function work?

I'm having trouble working with the setTimeout function, as it doesn't seem to be functioning properly. First and foremost, Player.prototype.playByUrl = function (url) { this.object.data = url; return this.play(); } The co ...

Communicating between iframes and parent elements via events

I'm trying to trigger an event in my iframe using the following code: $('body').trigger('my_event'); However, I want to bind this event on my main page that contains the iframe like this: $('iframe').find('body&ap ...

I am facing an issue with Angular where the $http.get method is

It seems like there must be a small oversight causing this apparently simple problem. I have a function that interacts with the Spotify API to search for an artist. I know that by accessing the corresponding route using a standard URL, a result is returne ...

When using jQuery AJAX, the script is returning blank values

Facing a frustrating issue here. I'm sending an AJAX request to a PHP file, but when I check Chrome Network Tools, it doesn't return any JSON data. However, when I try posting the same data using POSTMAN in Chrome, it returns correctly. Also, if ...

Creating dynamic grids in React.js by utilizing HTML

Currently, I am tackling one of the projects on FCC which is the Game of Life. Prior to diving in, my focus is on figuring out how to render a grid on the page. I aim to modify the table dimensions while ensuring it fits neatly within its container. The ...