Mobile applications use notifications as an unobtrusive way of informing the user that some application specific event has happened. Notifications are typically used to notify the user of the status of an application process that is running in the background. An example of this might be downloading a large file. This file might take a long time to download, so this activity should occur in the background. When the download is complete, the user is informed of the fact by a notification. Additionally, notification ares not just limited to local applications. It is also possible for server applications to publish notifications to mobile applications. This article will discuss how to use notifications on both Android and iOS
There are two types of notifications - local notifications and remote notifications (also known as push notifications). Local notifications are scheduled by applications running (or backgrounded) on the device that notify the user that an event of interest has occurred.
Remote notifications are lightweight messages that are sent from a server or application to a mobile application over a network. They provide an efficient way to notify a mobile application with updates from the cloud. For instance, consider an email application. In order to make sure that the email application is up to date with the latest emails, it has to poll a server every so often and check for new email. Polling in an application is an inefficient technique because must make frequent and expensive network calls.
Push notifications are designed specifically for this type of scenario. Instead of having individuals application continuously poll various servers for data, the OS will poll a single endpoint as part of its normal network operations.
However, remote notifications do add significant complexity in terms of effort, and infrastructure, and configuration. They require a separate application (typically running on a server) that will send notifications to a notification service. The notification service, in turn, identifies devices that are to receive the notification and delivers them in an efficient manner.
Each mobile operating system has it's own infrastructure and API's for remote notifications. Apple uses the Apple Notification Push Service to support remote notifications on iOS devices, while Google provides Google Cloud Messaging to enable messaging on Android devices.
To address the server side complexity of supporting two disparate notification services, there are a number of 3rd party libraries our there that simplify sending remote notifications, including:1. PushSharp - PushSharp is an open-source, community-contributed .NET library that provides a cross-platform abstraction that allows server applications to use a single API that will communicate with either the Apple Notification Push Service or Google Cloud Messaging. This library will be referred to throughout this article.
- Urban Airship - This is a commercial service that can provide push notifications for both Android and iOS applications. It also provides a web based GUI that can be used for creating notifications and for the rules surrounding when the notifications should be delivered.
- Windows Azure - This is another commercial service that allows for push notifications to be sent to mobile devices.
In this article we will examine both local and remote notifications on Android and iOS. We will first look a how local and remote notifications work in iOS. We will learn about the steps required to setup push notifications in the Apple Notification Push Service and how iOS applications can respond to these notifications. After that we will move on to examine how to perform the analog in Android, including local notifications and remote notifications via Google Cloud Messaging.