2014-11-14

This tutorial is the third part of a three-part series on how to do push notifications integration with your app for android and iOS.

Install the PushPlugin phonegap plugin from its github location via the Cordova CLI:



PushPlugin Phonegap Plugin

Add iOS and android platform using cordova CLI.



cordova platform add

Locate the PushNotification.js file that was installed into your project-root/plugins folder. This file must be copied into your project-root/www/js folder and referenced from the index.html currently.

https://github.com/phonegap-build/PushPlugin/blob/master/www/PushNotification.js



copy from phonegap plugin folder

copy to www folder

Write custom script for push notification plugin. Grab project id from Google Developer Console and put it inside this script. After that save as PushCustom.js in www/js.

Add the following script line to your index.html to reference the PushNotification.js and PushCustom.js.

Build and run the application via eclipse (ADT installed) and Xcode6.

Open your editor and create a file called simplepush.js.

Android setting

Go to your GCM console and locate the Server API key (click the API Access link in the menu on the left to locate they keys). http://blog.revivalx.com/2014/08/29/implement-push-notifications-for-android-and-ios-phonegap-part-1/

Get the registration id returned to our application from the console. I like to use the Android adb tool so I can run logcat to watch the console while my application is running. Assuming you have the android-sdk tools and platform-tools set on your environment path you can simply run adb logcat from the command line to show your device log.

Replacing the Sender key and device registration id with yours in simplepush.php.

IOS setting

Go to your apple developer account and locate iOS / APNs development certificates and provisioning profile then install it into your machine.

Get the token id returned to our Xcode console. Open your editor and replacing the token id and passphrase.

Now type the following from the command line where the script was created to run the code and send a push notification:
php simplepush.php

You should hear the notification and see it in your status bar like this on your Android and iOS devices.

Show more