Unified Multi-Platform Push Notifications with IBM MobileFirst

Push notifications, love them or hate them, are everywhere and there’s no getting around it. Push notifications are short messages that can be sent to mobile devices regardless of whether the apps are actually running. They can be used to send reminders, drive engagement with the mobile app, notify completion of long running processes, and more. Push notifications send information to you in real time, rather than you having to request that information.

Regardless of the platform or native/hybrid development approach, push notifications have to leverage the messaging infrastructure of the platform. iOS apps that have push notifications must use APNS (Apple Push Notification Service), Android apps must use GCM (Google Cloud Messaging), Windows Phone apps use MPNS (Microsoft Push Nofitication Service), and others use SMS gateways.

If you are building a back-end infrastructure to manage your application’s data, and you want to leverage push notifications, then guess what? You also have to build the hooks to manage subscription and distribution of push notifications for each platform.

If you’re building your app with IBM MobileFirst, guess what? You already have a unified API to communicate with all of these platform push notification services with a single API. Yes, you read that correctly – in addition to operational analytics, remote logging, simple data adaptersmobile application sharing, app management, encrypted offline storage, SSO, and support for both native and hybrid paradigms, IBM MobileFirst also has a single, unified multi-platform push notification API that simplifies your development effort for subscribing and managing push notifications on numerous platforms. Check out the video below for additional detail.

The unified push notification API allows you to develop your app against a single API, yet deliver push notifications to multiple platforms, and it works with both hybrid (HTML/CSS/JS) apps, as well as native apps.

MobileFirst Push Notification Mechanism
MobileFirst Push Notification Mechanism

 

The IBM MobileFirst push architecture supports numerous scenarios, including user targeted or broadcast messages.

You will still have to build the logic to subscribe devices for messaging, and dispatch push notification messages, but you’ll only have to do it once against the unified API – not once for each platform.

The apps that I showed in the video above are sample apps taken straight from the IBM MobileFirst platform developer guide for iOS and Android, and can be accessed in their entirety (with both client and server code) using the links below:

The client-side code will vary slightly depending on the native platform or hybrid approach, but the server-side implementation will be exactly the same.

When configuring your server for sending push notifications, be sure to follow the platform-specific steps to provision the apps/server for sending and receiving push notifications.

Within an adapter service on the MobileFirst server, you need to define an event source for push notifications.

[js]WL.Server.createEventSource({
name: ‘PushEventSource’,
onDeviceSubscribe: ‘deviceSubscribeFunc’,
onDeviceUnsubscribe: ‘deviceUnsubscribeFunc’,
securityTest:’PushApplication-strong-mobile-securityTest’
});[/js]

On the client app, you’ll need to subscribe for messages from the event source. See the hybrid or native code linked to above for syntax and examples.

Once your clients are subscribed, you can use a single server-side implementation to distribute messages to client apps. Below is an excerpt from the sample application which demonstrates sending a push notification to all devices for a particular user (on any platform):

[js]function submitNotification(userId, notificationText){
var userSubscription =
WL.Server.getUserNotificationSubscription(‘PushAdapter.PushEventSource’, userId);

if (userSubscription==null){
return { result: "No subscription found for user :: " + userId };
}

var badgeDigit = 1;

var notification =
WL.Server.createDefaultNotification(notificationText, badgeDigit, {custom:"data"});

WL.Logger.debug("submitNotification >> userId :: " + userId + ", text :: " + notificationText);

WL.Server.notifyAllDevices(userSubscription, notification);

return {
result: "Notification sent to user :: " + userId
};
}[/js]

From the MobileFirst console, you will be able to monitor and manage event sources, platforms, and the devices that are consuming push notifications.

Push Notifications on the MobileFirst Console
Push Notifications on the MobileFirst Console

 

If you were wondering, yes, these can be cloud-hosted on IBM BlueMix and yes, it can also be installed on-premise on your own server in your data center.  You have the option to configure your physical or cloud servers however you want.

Not sure where to go next? Maybe these will help: