Blog

Push Notifications in Mobile Applications

sivab
by  sivab
08 Nov, 2019
Xebia Background Header Wave

Overview

Push notifications are messages that are typically used to update customers and users about any important changes, updates, or status through their mobile / desktop devices.

These messages can be of a generic nature or personalized for a specific user. Businesses can enhance the user experience by sharing only personalized messages, rather than annoying them with all sorts of generic messages. The following criteria are considered before sending push notifications:

  • appropriate content based on user profile
  • time based on users geographical location and time zone
  • language based on the location of the device/user

Push notifications can be delivered to mobile devices, browser applications and desktop applications.

Service Providers

OSPNS (Operating System Push Notification Service)

There are multiple Operating System Push Notification Service providers such as:

  • Amazon Device Messaging (ADM) – this service is used to send push notifications to users of Amazon devices, such as Kindle tablets and other devices that run amazon apps.
  • Apple Push Notification Service (APNS) for both iOS and Mac OS X
  • Baidu Cloud Push (Baidu) – this service enables you to send push notifications to millions of mobile devices in China
  • Firebase Cloud Messaging (FCM) for Android devices
  • Microsoft Push Notification Service for Windows Phones (MPNS)
  • Windows Push Notification Services (WNS)

OSPNS provides unique device tokens to send push notifications by backend application servers.

Message Service Providers

Some of the commonly used cross-platform service providers for push notification messages are listed below:

  • Firebase Cloud messaging
  • Amazon SNS
  • Carnival.io
  • OneSignal
  • Kumulos
  • Pushwoosh
  • Urban Airship
  • Leanplum
  • Intercom
  • SWRVE
  • Mixpanel
  • Catapush
  • Taplytics

Mobile Push Notifications

Mobile apps are broadly categorized into 3 types:

  • Native Apps (Java/Kotlin, Objective-C/Swift)
  • Hybrid Apps (Ionic-Cordova, React Native, Flutter, Native-Script)
  • Progressive Web Apps (Html/Java-script web apps)

Even though all these apps receive push messages, they differ in their approach to register, receive, and handle messages. Irrespective of the type, every mobile app has to register with their OSPNS for generating a unique device token, which has to be shared with the Application backend for sending push messages to the respective devices. Every message service provider has their own pros and cons, and application backend can use any of the above Push message service providers for sending push to the user devices.

At coMakeIT, we have mostly used FCM as push provider for cross platform Android and iOS mobile applications, and used native APNS for some iOS applications.

Push Notification Flow (Native App & Hybrid App using Firebase)

Figure 1 – Native Mobile App Push Flow

Figure 2 – Ionic Mobile App Push flow with FCM

The procedure for implementing Push notifications for Ionic mobile App using Firebase is explained below (refer figure-2 above):

Registration

  • In both Native and Hybrid platforms, applications will first register with OSPNS to get the unique device tokens.
  • In case of firebase in iOS, as an extra step, iOS app has to send the unique device token it receives from the APNS and gets an Firebase in exchange. This token is used by FCM to send the push to the APNS and to the device finally.
  • These device tokens are shared with the Application backend and stored in the database along with device and user information. Registration for push is completed with this step.

Messaging

  • When an event occurs, application backend will have to initiate a push message flow. Backend can be selective on who is supposed to get the push for this specific event as it has user and device information along with device tokens.
  • After deciding the target users, backend fetches all the device tokens of that specific user or group.
  • Backend should build the Push message payload. This payload will have the basic requirements, like Title, Body, Sound, Image and some custom fields. Payload is built including device tokens and event details. Custom fields should have minimum information for the mobile application to know about the event. This payload might vary based the device OS.
  • Backend has to communicate first with FCM with the payloads for the both Android and iOS platforms. After which FCM forwards the push to the APNS in case of iOS or to the device for Android. In case of Native apps backend will send payloads directly to Messaging servers FCM and APNS for Android and iOS respectively.
  • These messaging servers (FCM and APNS) will set received messages in queue for sending to the user devices and return with success or failure responses to the backend. Batch of push messages can also be sent to messaging servers.

The delivery of messages can be made instant or scheduled for future by customizing the payload accordingly.

For Native apps, integration of push notifications integration is relatively easy and features like background push are easily supported, which means, push messages reach the application handlers even when app is not in foreground. But in case of Ionic apps, the app has to be in foreground to consume push notification data. Though there are some work-arounds to achieve the same functionality, it is not straight forward.

We used following plugin for integration of Push using firebase in Ionic-Native mobile application. https://ionicframework.com/docs/native/push. This plugin is feature-rich, well maintained and documented for push.

Firebase

Firebase is a package of Google Cloud Services, which has multiple applications to address modern use cases, such as:

  1. Data base – Fire-store & Realtime NoSQL based DB (Fast and Realtime Synchronization and offline support)
  2. Google Functions (Similar to lambdas for no backend services)
  3. Cloud Messaging (Push messaging and in-app messaging)
  4. Analytics (Machine learning)
  5. Mobile Crash logging (Application logging and Crash detection)
  6. Authentication Services (OAuth and OpenID services )
  7. Dynamic links (Content based dynamic links for user engagement)

sivab
Software Engineer at coMakeIT
Questions?

Get in touch with us to learn more about the subject and related solutions

Explore related posts