Push your app to the limit: Using RhoConnect PUSH service as a G2CM Alternative

Kutir Mobility -
7 MIN READ

What are push notifications?

If you are already familiar with the concept of push notifications, skip to the next section for information on how to get started using them in your own app.

The concept of a "push notification" is simple: instead of having your application continuously asking the server "is there anything I should know about?" ("pulling" information from the server), the server instead notifies the application when an event of interest occurs. The name "push notification" comes from the fact that the server "pushes" the message to the client instead of passively waiting for the client to initiate a connection.

Another advantage of push notifications is that users will receive the notification even if a particular application is not currently running: if you are developing an application for keeping track of to-dos and a manager assigns a task to an employee, the employee will receive the notification even if he is not currently working with the to-do application.

What devices and OSs support which push mechanism? The reason for the existence of RhoConnect Push

The concept of a server-initiated notification has been around for a long time in one form or another and most current mobile operating systems offer their own facilities for handling notifications. The differences between platforms are significant, with some platforms supporting several alternatives and others not providing any out of the box:

iOS offers its own Apple Push Notification Service and disallows the use of any other push service.

Android devices with the Google Play Store (most consumer-oriented devices fall in this category) include Google Cloud Messaging (GCM) , "a free service that helps developers send data from servers to their Android applications on Android devices, and upstream messages from the user's device back to the cloud".

Android devices from OEMs like Motorola Solutions may not include the Google Play Store or more holistically - Google Mobile Services or GMS for short. Google Cloud Messaging requires these services in order for it to work, which means most enterprise-oriented devices like the ET1, MC40 and most versions of the TC55 do not provide native push capabilities. The reason for this omission is that most enterprises do not want to be bound by Google's Terms of Service for one reason or another and the unfortunate consequence is that developers need to implement their own push solution. RhoConnect Push Service is the logical alternative to Google Cloud Messaging in this case.

Windows Mobile does not provide any native push notification capabilities and, again, RhoConnect Push Service saves the day.

RhoConnect Push Service was born out of the necessity to provide push notifications on every platform, irrespective of their native capabilities. In a nutshell, RhoConnect Push Service is a seamless way for your application to receive push notifications where the native platform falls short. It is available on Android (both on devices with the Play Store and on those without it like the TC55 and MC40) as well as on Windows Mobile.

Here are your options for using push notifications today:

Platform Native RhoConnect PUSH
iOS YES NO
Android devices with GCM (consumer) YES YES
Android devices without GCM (enterprise) NO YES
Windows Mobile NO YES

As you can see, on iOS the choice is clear: you have no option but to use Apple's APNS service. Windows Mobile does not leave much to the imagination either: since it has no native notification capabilities, you have to either implement them yourself or use RhoConnect Push Service.

The waters are slightly murkier on Android: some devices (mostly consumer-oriented) support Google's notification service, but most enterprise devices like the MC40 and TC55 do not. Furthermore, in the case of the TC55, there are versions of the device with Google's services and versions without them. However, you do not want to maintain two separate code bases or unnecessarily limit your app to only one particular version or device, plus you may be required to support different devices in the future.

RhoConnect Push Service was developed to solve this exact problem, freeing you from the differences in notification capabilities across devices and helping you bring your application to market more quickly. Enterprise mobile applications that need push notifications should use RhoConnect Push Service if they are targeting enterprise-grade devices, as this provides the most flexibility for deployment on all types of devices. In the next section you will learn how to integrate RhoConnect Push Service on an application designed for the MC40 or TC55 and the exact same steps and code can be used for deployment on any other Android device.

RhoConnect Push walkthrough. From nothing to push-enabled app in 10 minutes.

Once you have decided to give RhoConnect Push Service a try, you will find that setup and implementation are surprisingly straightforward, with just a handful of steps to complete and very little code required on your part.

Installing Rhoconnect and RhoConnect Push Service.

Refer to the official documentation on RhoConnect Push Service. In short, you need to complete two steps:

  • Install RhoConnect and RhoConnect Push Service on your server (for the purpose of this tutorial, install them on your local machine). While following the instructions, you will reach a point where you have to edit the settings/settings.yml file and assign the push_server. Instead of "someappname", use "rhoconnectpushtest" as shown below and make a mental note to remember this value, as you will use it again shortly on your mobile client:

    :push_server: http://rhoconnectpushtest@localhost:8675/

  • Install RhoConnect Push Client on your TC55, MC40 or other mobile device. Again, refer to the RhoConnect Push Service documentation where you will find step-by-step instructions of where to find the files you need to install and how to install them.

    Once the services are configured, start them:

  • start rhoconnect with

    rake redis:start

    rhoconnect start

  • start rhoconnect push with

    rhoconnect-push

Configuring your app to handle push notifications

Now that the server is ready, let's build a client to go with it. Start by creating a new RhoMobile app with

rhodes app pushtest

then edit rhoconfig.txt and configure the following values, making sure to substitute 192.168.1.2 with the IP address of your computer.

syncserver = 'http://192.168.1.2:9292'

Push.rhoconnect.pushServer = 'http://192.168.1.2:8675'

Push.rhoconnect.pushAppName = 'rhoconnectpushtest'

The pushAppName parameter must match the one we configured above in "push_server". In a production environment, please use a different value and treat it as a sort of authentication token that should not be disclosed publicly.

Edit app/application.rb and add the following code at the end of the "initialize" method:

Rho::Push.startNotifications '/app/Settings/push_callback'

This tells RhoMobile which action to invoke when a push notification is received.

Now edit app/Settings/controller.rb and add the following code:

def push_callback

  Rho::Notification.showPopup({'message' => @params['alert'], 'buttons' =>['OK']})

end

This is the code that will receive the notification. For now, we will just show a popup, but your application can do anything you need. A common use case is to use a push notification as a trigger for the app to synchronize data with RhoConnect.

Testing notifications

Now that all the pieces are in place, it's time to see notifications in action! Please note that you will need to install your application on an actual device, you will not be able to test notifications on RhoSimulator. Start your app on a mobile device and log in with any username and password. The easiest way to test notifications is from within RhoConnect's own admin console. Point your browser to http://localhost:9292/console , click "login" and go to the "Users" tab. Click the "Ping users" button, edit the message and click "Ping!". Now look at your mobile device and you should see a popup message, just as you would expect from the code in the "push_callback" method.

What's next

Testing notifications manually is fine during the initial stages of development. Once you move past that point, you may be interested in looking at the RhoConnect REST API, which allows you to send notifications programmatically. Additionally, in a future post we will cover how to use RhoConnect Push Service in a native Android (non-rhodes) application. If you want to handle these push notifications in a native Android application, you can write a very trivial RhoMobile application that simply is configured to receive the RhoConnect Push notification, as previously mentioned, and then trigger an Android intent using the Rho.Intent API. Now whether you are writing RhoMobile applications or Native Android applications, you will be able to receive Push Notifications.

About us

Facing challenges with your RhoMobile implementation? Kutir Technologies, a Motorola Certified partner, can help you get your app done on time. Get in touch with us today at info@kutirtech.com , no strings attached.

profile

Kutir Mobility

Please register or login to post a reply

3 Replies

V Vedsatx Saddvv

I am no professional, but I suppose you just made an excellent point. It's a really nice information given here.

V Vedsatx Saddvv

push notification is not working properly in RhoMobile so can you please suggest any proper link to follow step wise

V Vedsatx Saddvv

push notification is not working properly so can you please suggest any proper link to follow step wise