📜 ⬆️ ⬇️

Getting started with Push Notifications in PhoneGap

Good day, habra users!

Push notifications are not included in the PhoneGap API. If you do a small search on the PhoneGap documentation, then you can find only Notifications, which are usual alert dialogs with the possibility of using sound effects and vibrations in them.
But what if you just need to create a cross-platform application with Push Notifications? I want to draw your attention to a test example of working with some of them using Android. As a result, iOS, BlackBerry and Windows Phone applications will also be available from the developed project.

image

The article will look at two libraries for working with Push Notifications in PhoneGap: Urban Airship and Poosh Woosh.
')
You should start by searching for a suitable library, and there are actually a great many of them. However, it is necessary that the library be truly cross-platform and have a single delivery service.

After reviewing the available options, I stopped at 2 libraries: Urban Airship and Poosh Woosh. They have their own advantages and disadvantages, therefore we will consider both libraries.

In fact, Urban Airship has 3 versions: Enterprise Edition, Small Business Edition for small business and free Developer Edition. You can familiarize yourself with all the advantages in more detail on the official website .

Push Woosh also has several versions: Free, Premium, Gold, Platinum. You can get acquainted with them after registering on the official website .

Consider the free versions in more detail: the Developer Edition from Urban Airship and Free from Push Woosh. Their main difference is that in Urban Airship you can send up to 1 million messages per month, and in Push Woosh you can connect to send messages up to 1 million devices. In addition, in the free version of Push Woosh, you will not have access to the API, geofences and tags, and the number of applications will be limited to 10. Urban Airship has the advantages of its product: flexible interfaces for full customization, reliability, security, scalability, and high performance. So, you can choose the one that is more suitable for your project.
Next, let's move on to connecting libraries.

Google?


Yes, it is Google. Now it is worth turning to his help. You will need to use the Google API for your project. For this:
1. It is necessary to follow the link and create it, respectively;

image

2. After creating the project, a link similar to this one will be entered in the browser:

https://code.google.com/apis/console/#project:4815162342 

Here, 4815162342 is the gsmSender in the airshipconfig.properties file.
3. In the Services tab, you must enable Google Cloud Messaging for Android.



4. In the API Access tab, select “Create a new Server key ...” In the window that appears, do not need to enter anything, just click “Create”.



5. The generated API key will be needed in the Urban Airsip profile created earlier.



Go urban airship


Now, you should download the library itself, as well as a test case from the official Urban Airship website . We connect the project to Eclipse and add the downloaded library to it.
Next you need to do the most interesting thing - deal with the keys that are in the airshipconfig.properties file.



Go to the Urban Airship profile and create a new application in it, while entering the resulting API key into the CGM API Key line.


In the Details tab of the created project: Application Key is developmentAppKey in the airshipconfig.properties file, and Application Secret is developmentAppSecret.



And then came the moment when, finally, you can run the application. At the same time do not forget to turn on the Internet.
To send Push Notifications, you must do the following steps:

1. Read the log and see a similar line. Copy the push ID that you need to send Push Notification to the specified phone.



2. In the profile, go to the Push -> Test Push Notifications tab and select Android. Here, in the Apid line, enter the copied push ID, in the Extra key - the Application Key, and in the Extra value - the Application Secret. Alert is the message that needs to be transmitted.



3. Check - click “Send it!”. When clicking on Push Notifications there is a transition to the application itself.



Pushwoosh


In working with Pushwoosh, everything is very similar.
You can download a test case for PhoneGap.
You will need to register and create an application. For an example of working with an application, enter the API key obtained from Google.



Next, in the code of the index.js file, we replace the projectId with our own; in the appid field, enter the code we received from PushWoosh:



Now you can send the first Push Notification from Push Woosh (for this you do not need to enter additional codes for devices).

Source: https://habr.com/ru/post/171087/


All Articles