APNs enables iOS push notifications. This guide covers APNs implementation with Node.js.
Setup
Generate Certificates
- 1Create App ID in Apple Developer Portal
- 2Enable Push Notifications
- 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.