What is push and why is it important?
People used to access a browser for information, but now they download an application and expect it to send them information when they need it. With push notifications, the application can still talk to people when the application is closed. Users are also more responsive to push notifications as compared with email or text messages (source). Push notifications are not only a useful way to communicate with users– they can be used to save battery life because information can be passed directly to the phone rather than the phone constantly polling for data.
Before you begin
You will need the following to add push notification functionality to your app:
- Mobile Application (Native iOS, Native Android, Phonegap, etc…)
- An Application Server (Server that holds your app’s data and sends pushes)
- Database (Stores user data and push tokens)
We assume you have already planned for the following:
- Plan to handle risk management and disaster recovery
- Business understands push notifications do not have a feedback service
How push works
At a high level, sending a notification looks something like this:
All pushes go through a push notification provider, which is determined by the operating system of the push you’re trying to send to. Apple’s iOS uses a service called Apple Push Notification Service (APNS) and Google’s Android uses one called Google Cloud Messaging (GCM, formerly known as C2DM). Windows Phone uses Microsoft Push Notification Service (MPNS). The push originates from your application server, which sends the message with an identifier to the push provider that relays the push to the desired device.
Registering with the push notification service (Apple, Google, etc)
You will need to register your application with the push notification service to send pushes to your application on a device. When your application server sends a push to the push notification service, you will use the credentials that you got from this step.
Registering the device for push (get token)
In your application, you need to request a token from the push notification service. This token represents your application running on a specific device, and when your application server wants to send a push to that device, it will use this token. At a high-level, registering looks very similar to the following diagram:
Sending the token to the application server
When you receive a token from a push service, you need to send this token to your application server so that you can send messages using the token. If you are using Urban Airship or another push provider, you will need to send this token both to Urban Airship and your own server, as shown by the following diagram:
How to send a push from the application server
Your application server will need to make a call to the push notification service using the service’s API. If you’re using Urban Airship, your application will send to the push there, and Urban Airship will then forward that information to the push notification service.
How to handle a push on the device
Pushes are sent to the device and then the operating system will pass that information onto the application. It is the developer’s responsibility to determine what will happen when the push is received. Apple and Google have some major differences at this point, which will be explained in their respective pages. There are three general use cases that can occur:
Where to go from here
We created a push notification framework for incorporating push notifications in Native Android, Native iOS, Phonegap iOS and Android, Rhodes, and Unity platforms. We selected Urban Airship from a list of push providers. We also created an application server from which to send these notifications. Each application section includes general information for where to begin when creating an application and general tips and tricks we found through our development.