iOS
Push Notifications
Mobile Development
APNs
Apple Notifications

How do iOS Push Notifications work?

Interview Questions practice on Codemia

Over 8,000 real interview questions from top companies, searchable by company and role.

Browse interview questions

Introduction

Push notifications have become an integral part of user engagement in mobile applications. They are real-time messages sent directly to a user's device that can provide updates, remind users of pending tasks, or engage users with personalized messages. Apple's iOS push notification service, APNs (Apple Push Notification service), is a robust system that developers use to deliver these notifications. This article delves into the mechanics of iOS push notifications, providing both a technical overview and insights into the process.

How iOS Push Notifications Work

iOS push notifications rely on the interplay between your app, a server, and Apple's APNs. Here's a step-by-step breakdown of how they work:

  1. The Setup:
    • An iOS device registers with APNs and receives a unique device token.
    • This device token acts as an address to which notifications can be sent.
  2. Sending a Notification:
    • A backend server is configured to create notifications and send them to APNs.
    • These notifications include the device token, your alert or message, and any additional data like custom payload data.
  3. APNs Role:
    • Upon receiving the notification from the server, APNs takes on the responsibility of delivering it to the device.
    • This ensures that the notifications are low-latency and reach the intended recipient promptly.
  4. Device Reception:
    • Once the notification is delivered to the device, it is displayed on the lock screen, notification center, or as a banner, depending on user settings.
    • The app can be opened directly via the notification.

Technical Details

iOS push notifications have a structured JSON payload that specifies how the notification should be displayed and what data it carries. Here is a simplified payload example:

  • aps dictionary: This is a reserved namespace for APNs. It contains keys like `alert`, which holds the notification's text, `badge`, representing the application badge count, and `sound`, specifying a custom or default ringtone.
  • Custom Data: Additional data can be included to provide more context. For example, the `conversationId` could be used by the app to identify which chat to open when the user taps the notification.
  • Efficiency and Reliability: APNs is optimized for efficiently delivering messages, maintaining a persistent and secure connection between the device and the service.
  • Adjustable Content: Developers can configure notifications as silent (which do not display alerts but instead update the app content in the background).
  • User Customization: Notification behavior can be tailored by users or developers, setting sounds, badges, or lock screen preferences.
    • The app sends a request to APNs for a device token.
    • Once received, this token is sent to the backend server.
    • The backend server provides a connection to APNs, using this token to direct notifications to the appropriate device.
    • APNs manages the delivery of push notifications from the server to devices, ensuring messages are transmitted even when apps are closed or the device currently offline (APNs will attempt to deliver the message when the device reconnects).
    • Upon interaction with the notification, the app can be launched or brought to the foreground, and additional actions can be processed based on the included data.
  • Security: Protecting user data is paramount. Generally, notifications should not contain sensitive information and should be encrypted accordingly.
  • User Permissions: Users must explicitly permit an application to send notifications. Applications should seek permission gracefully and inform users about what’s being asked.
  • Notification Overload: Sending frequent notifications may annoy users, leading to app uninstalls or notification disabling.

Related reading
Free course
Beginner
7 lessons
2 hours
Tackling System Design Interview Problems

A short course that equips you with the skills to approach system design interviews methodically.

Start the free course
Track what you have practised

A free account saves your progress, solutions and study plan across every problem on Codemia.

Interview Questions practice on Codemia

Over 8,000 real interview questions from top companies, searchable by company and role.

Browse interview questions

All Rights Reserved.