How iOS Push Notification works
We’re so used to receiving them but how many iPhone, iPad and other iOS device users know how push notifications actually work? I thought it might be time to find out.
What is a push notification?
The reminder you receive from Apple Calendar letting you know an event is taking place, a warning that you’ve just received a message from a friend or an app letting you know your flight is about to leave – all of these are examples of notifications taking place on iOS devices.
You’ll receive them as banner alerts, notes on the lock screen or in the notification center, or all three.
You control these in the Notifications section of iOS Settings, and when you first install and use an app you may be asked if you want to enable it to send push notifications to you.
iOS lets you receive two forms of notification, Local and Push.
The first set are handled by the app on our device with little additional input (so that’s the notification you might receive when you get an email), while Push notifications are triggered by another service, such as a web server of some kind.
In other words, while both types of notification may seem to be the same, push notifications are slightly different in they are generated off your device.
When did Apple introduce push notifications?
Apple introduced these things with iOS 3 in 2008, but rollout was delayed.
At the time, the company was looking for a way to let you receive messages in real time without having to run the app in the background, or constantly poll for messages, both of which consumed way too much power.
Here are some of the things that can happen on your device because of Push notifications
- Display text messages.
- Play notification sounds.
- Set a badge number on an app icon.
- Provide actions the user can take without opening the app.
- Show an attachment.
- Handle a task in the background.
- Group notifications.
- Edit or remove notifications.
- And more.
That’s all great, but what is actually happening when you receive one of these?
How iOS Push Notifications work
If you are using an application that has push notifications enabled, those notifications must go through the following process to get to you:
- Get sent to Apple by the provider
- The notification is received by the Apple Notification Servers (APN servers).
- The APN server then routes the notification to the correct device(s). So, a notification intended only for you and your device would only be sent to you, while the APN Server may send group notifications to lots of people.
- The messages are quickly delivered to the target devices.
On initial launch of an app on a user’s device, the system automatically establishes an accredited, encrypted, and persistent IP connection between the app and APNs, though developers must follow several more steps in order to implement push notifications.
How to implement push notifications
For a developer, implementing push notifications requires several steps. These are well explained in this App Code article, but I thought some readers may like a very brief synopsis:
- Make a Certificate Signing Request (CSR) in Keychain on the Mac.
- Create an App ID, which will help APN servers know which app is asking to send Push notifications.
- Configure the App ID for push notifications, during which you’ll need to configure the CSR you got using Keychain.
- You will then add your completed CSR to Keychain on your Mac.
- Register your device and create a new provisioning profile. During this process a developer will hardwire their app to the APN servers, which is required for push to work.
- Configure the project by enabling Push Notifications and set up the parameters for this.
- Register for Push notification, experiment with them and define appropriate response behaviours for when the app receives a notification.
- Once complete, try it live within an app.
It’s all about trust
The idea is that because the developer has hard wired the connection between their app and app servers and Apple, it is possible for them to send Push notifications to Apple for private, secure distribution to the users of the app.
Users should feel secure the notification is valid, and developers know that the notification they are trying to send will reach their target customers.
As Apple puts it:
“Trust between APNs and each device is established automatically, without participation by your app, as described in this section.
“Each device has a cryptographic certificate and a private cryptographic key, provided by the operating system at initial device activation and stored in the device’s keychain. During activation, APNs authenticates and validates the connection to the device.”
Further reading
- You can explore Apple’s complete guide to help developers implement push notifications here.
- You’ll find a complete account of how to build push notifications within your app here.
Please follow me on Twitter, or join me in the AppleHolic’s bar & grill and Apple Discussions groups on MeWe.
Dear reader, this is just to let you know that as an Amazon Associate I earn from qualifying purchases.