Apple Push Notification Service, as the name suggests, is a notification delivery service provided by Apple.

Apple provides two authentication methods to make a secure connection to APNs. The first is Certificate-Based Authentication (using a .p12 certificate). The second is Token-Based Authentication (using a .p8 key). We’ll make use of the .p8 key.

To enable APNS integration, you need to create an Apple Developer account with an Admin role.

To generate the p8 key for your account:

  1. Head over to Certificates, Identifiers & Profiles > Keys.
  2. Register a new key and give it a name.
  3. Enable the Apple Push Notifications service (APNs) checkbox by selecting it.
  4. Click the Continue button and on the next page, select Register.
  5. Download the .p8 key file.

You also need the following to connect to APNs:

  1. Key ID - This is a 10-character unique identifier for the authentication key. You can find it in the key details section of the newly created key in your Apple developer account.
  2. Team ID - This is available in your Apple developer account.
  3. Bundle ID - This is the ID of your app. You can find it in the app info section of your Apple developer account.

The overrides field supports all Notification payload values, as shown below:

import { Novu } from '@novu/node';

const novu = new Novu("<NOVU_API_KEY>");

novu.trigger('<WORKFLOW_TRIGGER_IDENTIFIER>', {
  to: {
    subscriberId: '<SUBSCRIBER_ID>',
  },
  payload: {
    abc: 'def', // If the notification is a data notification, the payload will be sent as the data
  },
  overrides: {
    apns: {
      payload: {
        aps: {
          notification: {
            title: 'Test',
            body: 'Test push',
          },
          data: {
            key: 'value',
          },
        },
      },
    },
  },
});
import { Novu } from '@novu/node';

const novu = new Novu("<NOVU_API_KEY>");

novu.trigger('<WORKFLOW_TRIGGER_IDENTIFIER>', {
  to: {
    subscriberId: '<SUBSCRIBER_ID>',
  },
  payload: {
    key1: 'val1',
    key2: 'val2', // If the notification is a data notification, the payload will be sent as the data
  },
  overrides: {
    type: 'data',
    apns: {
      headers: {
        'apns-priority': '5',
      },
      payload: {
        aps: {
          alert: {
            'loc-key': 'GAME_PLAY_REQUEST_FORMAT',
            'loc-args': ['Shelly', 'Rick'],
          },
          sound: 'demo.wav',
        },
      },
    },
  },
});

Before triggering the notification to a subscriber(user) with push as a step in the workflow, make sure you have added the subscriber’s device token as follows:

  • Node.js

  • cURL

import {
  Novu,
  ChatProviderIdEnum
} from '@novu/node';

const novu = new Novu("<NOVU_API_KEY>");

await novu.subscribers.setCredentials('subscriberId', PushProviderIdEnum.APNS, {
  deviceTokens: ['token1', 'token2'],
});

Checkout the API reference for more details.