Apple Wallet Push Notifications: Sending in logs but not appearing on phone

I am unable to receive push notifications through my Apple Wallet pass. Based on the documents I have read, I have set up my APN provider and should be sending all the necessary information. Furthermore, my logs show that I am successfully sending my notification to APN, so it is confusing that no notification appears on my phone. Below are my code snippets:

apnProvider.js:

const path = require('path');

const options = {

  cert: path.resolve(__dirname, '../certificates/signerCert.pem'),

  key: path.resolve(__dirname, '../certificates/signerKey.pem'),

  passphrase: 'test',

  production: true
};

const apnProvider = new apn.Provider(options);

module.exports = apnProvider;

APN provider using an auth key (currently not being used but was previously and provided the same success message):


  token: {

    key: path.resolve(__dirname, '../certificates/AuthKey_627HR2YX2S.p8'),

    keyId: "627HR2YX2S",

    teamId: "72J45J9PH3"

  },

  production: true
});

API Rout:


  const { userId } = req.body;

  console.log(`Received POST request on /api/send-notification for user`);

  try {

    console.log(`Sending notification to user: ${userId}`);

    const user = await User.findById(userId);

    if (user && user.deviceToken) {

      console.log('User Name:', user.firstName, user.lastName);

      console.log('Device Token:', user.deviceToken);

      let notification = new apn.Notification();

      notification.expiry = Math.floor(Date.now() / 1000) + 3600;

      notification.badge = 1;

      notification.sound = 'default';

      notification.alert = 'Hello World';

      notification.payload = { messageFrom: 'Kudjo' };

      notification.topic = 'pass.com.kudjo';

      console.log(`Sending notification to device token: ${user.deviceToken}`);

      console.log(`Notification payload:`, notification.payload);

      apnProvider.send(notification, user.deviceToken).then(response => {

        console.log('Push notification sent:', response);

        res.status(200).json({ message: 'Notification sent' });

      }).catch(error => {

        console.error('Error sending push notification:', error);

        res.status(500).json({ message: 'Error sending notification One' });

      });

    } else {

      console.log('User or device token not found');

      res.status(404).json({ message: 'User or device token not found' });

    }

  } catch (error) {

    console.log('Error sending notification:', error);

    res.status(500).json({ message: 'Error sending notification Two' });

  }
});

Thank you for your help!

Answered by DTS Engineer in 796510022

Hi @Ddud,

You wrote:

[...] Furthermore, my logs show that I am successfully sending my notification to APN, so it is confusing that no notification appears on my phone. [...]

Before we begin, I'd like to confirm that you've read the following documentation:

To send a pass update push notification, perform the following steps:

  1. Find the registered devices for the updated pass.
  2. Create and send a push notification for each registered device.
  3. Verify your notification matches the following criteria:
  • Uses the same certificate and private key that the creator of the original used for signing.
  • The push token registered by the device.
  • Contains an empty JSON dictionary for the notification payload.

For invalid push token errors, delete the associated device from APNs. For more information, see Sending notification requests to APNs.

Next, you wrote:

[...] token: { [...] } [...]

Please remove sensitive information from your post. Your team identifier and private key (or key identifier) should not be made available to the public.

Then, you wrote:

Update: I confirmed that my APN provider is through "openssl s_client -connect api.sandbox.push.apple.com:443". [...]

A push notification for a pass update works only in the production environment. The sandbox environment will not deliver notifications of this type. Please attempt to send the push notification in production and report back with the results.

Cheers,

Paris

Update: I confirmed that my APN provider is through "openssl s_client -connect api.sandbox.push.apple.com:443". Unfortunately, the Device Token Validator tool is saying my push token is invalid, and I cannot send a notification through the Push Notifications solution in the developer. It does say that I successfully send a notification on the 7th, but I cannot see to what device.

Hi @Ddud,

You wrote:

[...] Furthermore, my logs show that I am successfully sending my notification to APN, so it is confusing that no notification appears on my phone. [...]

Before we begin, I'd like to confirm that you've read the following documentation:

To send a pass update push notification, perform the following steps:

  1. Find the registered devices for the updated pass.
  2. Create and send a push notification for each registered device.
  3. Verify your notification matches the following criteria:
  • Uses the same certificate and private key that the creator of the original used for signing.
  • The push token registered by the device.
  • Contains an empty JSON dictionary for the notification payload.

For invalid push token errors, delete the associated device from APNs. For more information, see Sending notification requests to APNs.

Next, you wrote:

[...] token: { [...] } [...]

Please remove sensitive information from your post. Your team identifier and private key (or key identifier) should not be made available to the public.

Then, you wrote:

Update: I confirmed that my APN provider is through "openssl s_client -connect api.sandbox.push.apple.com:443". [...]

A push notification for a pass update works only in the production environment. The sandbox environment will not deliver notifications of this type. Please attempt to send the push notification in production and report back with the results.

Cheers,

Paris

Hi  @Ddud,

You wrote:

I changed my APN provider to use my certificate for my pass type id, which is now giving me this error: Failed to send push notification: { reason: 'TopicDisallowed' } [...]

For the TopicDisallowed error, please see Handling notification responses from APNs.

  • Status code: 400
  • Error string: TopicDisallowed
  • Description: Pushing to this topic is not allowed.

Next, you wrote:

[...] Do I us pass type id as topic? [...]

For token-based authentication via JSON Web Token (JWT), use the Pass Type ID as the push notification topic.

For certificate-based authentication, the notification topic should only be provided if the certificate is configured to support multiple APNs-based capabilities. If the certificate is used solely for PassKit and Wallet, its value can be omitted.

Then, you wrote:

[...] Should my APN use PTI certificate? [...]

You use the same certificate and private key for sending pass update push notifications as for signing passes.

In your initial post, you wrote:

Furthermore, my logs show that I am successfully sending my notification to APN, so it is confusing that no notification appears on my phone.

Change message updates are delivered to the device and appear to the user on the Lock Screen. Other pass updates, such as those containing relevant date and location messages are passive and are updated within Wallet or where a pass is displayed by the system after calling your webServiceURL.

Best,

Paris

Apple Wallet Push Notifications: Sending in logs but not appearing on phone
 
 
Q