Skip to content
All essays
iOSJanuary 15, 20265 min

Apple Push Notification Service (APNs) Guide

Complete guide to implementing APNs for iOS push notifications

Ü
Ümit Uz
Mobile & Full Stack Developer

APNs enables iOS push notifications. This guide covers APNs implementation with Node.js.

Setup

Generate Certificates

  1. 1Create App ID in Apple Developer Portal
  2. 2Enable Push Notifications
  3. 3Download .p12 certificate

Implementation

typescript
import apn from 'apn';

const options = {
  cert: './cert.pem',
  key: './key.pem',
  production: false, // true for production
};

const apnProvider = new apn.Provider(options);

export async function sendPush(deviceToken: string, notification: any) {
  const note = new apn.Notification();

  note.alert = notification.title;
  note.body = notification.body;
  note.sound = 'ping.aiff';
  note.badge = 1;

  return await apnProvider.send(note, deviceToken);
}

Conclusion

APNs requires proper certificates. Use sandbox for development, production for release. Handle token refresh for reliable delivery.

Enjoyed this essay? Share it.

Related essays

Next essay
Building a Scalable Email System with Node.js