Push Messages

A cross platform push messaging service for mobile applications

What is pushMobi?

pushMobi is a cross platform push messaging service for mobile applications. With a single code base you can send and receive push notifications on iOS, Android, Windows8 and Windows8 Phone. Along with the 160 characters of notification text, you also have the ability to send a 500 characters long secure message that can be accessed by your app and used to control a behavior or provide additional content.

Why use pushMobi?

Push messages have shown to increase user engagement in your app by both maintaining active users interest as well as enticing dormant users to come back to your app, through deals, offers and update notices.

Getting started using pushMobi

There are three basic steps to using pushMobi in your app.

  1. Initialize the AppMobi Cordova Plugin.

    Initialize the AppMobi Cordova plugin onDeviceReady() event is executed.

   function onDeviceReady() {
               initializePlugin();
            }
initializePlugin: function () {
 //The ldapUserName and ldapPassWord should be obtained from User in index.html.
 //These params can be passed as "" in case of security level 1 and security level 2.

 var ldapUserName="";
 var ldapPassWord="";

        cordova.require("com.appMobiCloud.AppMobiCloud");
        var launchImageID = document.getElementById('launchImage');
        launchImageID.style.display = 'block';
        AppMobiCloud.plugin.initialize(function (data) {//success callback
                    alert("AppMobi library initialized successfully");
                    var launchImageID = document.getElementById("launchImage");
                    launchImageID.style.display = 'none';
        }, function (data) {//error callback
                    alert(data.message);
                    var launchImageID = document.getElementById("launchImage");
                    launchImageID.style.display = 'none';
        }, ldapUserName,ldapPassWord);

  document.addEventListener('deviceready', onDeviceReady, false);
Required Parameters for initialization:
  • UserName & Password: Auth Credentials in case of Level3 Type of security is implemented. These Credentials will be authenticated against Server Configured.
  1. Check to see if user is registered, If not registered lets add the user.

Registering a user id on a particular device alerts the pushMobi service that the application is installed and ready to receive push messages. The first time a pushMobi-enabled application runs, it should establish a user identifier on the device for that particular appMobi application. The user identifier doesn’t necessarily have to be entered in by the user, since it could be generated randomly or based on the device ID. However, developers looking to reach users only once despite those users having several devices will have to make sure that the user id is unique to each human being who uses the application regardless of which device they are currently holding in their hand.

function checkPushUser(){
         var user = "my_username";
         var pass = "my_password";
         AppMobiCloud.notification.checkPushUser(user,pass);

 }
var onPushEnable = function(data){
         if(!data.success){
             var didAddPushUser = localStorage.getItem("didAddPushUser");
             if(!didAddPushUser){
                 AppMobiCloud.notification.addPushUser(user,pass,email);
                 localStorage.setItem("didAddPushUser", "true");
             }
         }
   }
document.addEventListener("appMobi.notification.push.enable",onPushEnable,false);
  1. Start listening for messages.

Once the application has successfully registered for push messages, the next step is to start looking for message events. The sample below is called from the code block above, and it will begin to listen for the appMobi.notification.push.receive event which indicates that a new pushMobi message is available.

/* This code runs when a push message is received */
var onPushReceive = function(data){
var myNotifications=AppMobiCloud.notification.getNotificationsList();
var len=myNotifications.length;

   if(len > 0) {
      for(i=0; i < len; i++) {
           msgObj=AppMobiCloud.notification.getNotificationData(myNotifications[i]);
           try{
           if(typeof msgObj == "object" && msgObj.id == myNotifications[i]){
             AppMobiCloud.notification.alert(msgObj.msg + "\n" + msgObj.data,"pushMobi Message","OK");
             AppMobiCloud.notification.deletePushNotifications(msgObj.id);
                        return;
                 }
               alert("Invalid Message Object: " + i);
             }catch(e){
                 AppMobiCloud.notification.alert("Caught Exception For: " + e.message);
                 //Always mark the messages as read and delete them.
                 //If you don’t, your users will get them over and over again.
                 AppMobiCloud.notification.deletePushNotifications(msgObj.id);
               }
            }
        }
    }

  document.addEventListener("appMobi.notification.push.receive",onPushReceive,false);