Push Notifications with IBM Worklight
bedfordsean 270005PJ7F Comments (2) Visits (16103)
IBM Worklight comes with built in push support for iOS and Android. This walkthrough should assist in the required set up for this.
For the purposes of demonstrating push notifications, we will use the sample code provided by IBM. You can download this from here - look for the "Push Notifications" topic, and download the sample code:
1. Once this code has been downloaded, import it into Eclipse.
2. You should now see the sample project:
iOS Set Up
Log on to your Apple developer account at
After ensuring this is the case, proceed to the App IDs section and create an app ID for your push application. Enter the settings similarly to those below. Please take note of the Bundle identifier you use here. It will be important later
After completing this step, go to your newly created app, and click "Configure". In this view, click the "Enable for Apple Push Notification service", and then click "Configure" for the development Push SSL Certificate. Follow the steps in the resulting wizard to generate a certificate signing request from the Keychain application and upload it to Apple. Once you have completed these steps, you should be presented with a screen similar to that below. Download the development certificate.
Once you have downloaded this certificate, add it back to the Keychain application by dragging it into the Keychain icon in the Dock.
Now you will need to export the public/private keypair you have just generated. Since you generated the certificate signing request on the same machine, this is where your private key is stored. Open Keychain, and look for the entry that matches the bundle identifier you set up, underneath the "Certificates" category. To ease finding it, you can type part of the bundle identifier into the search box.
Once you have found the certificate, expand it, right click on the key it contains and click export. This will allow you to save the public/private keypair as a p12 file. Name this p12 file apns
Once you have got the p12 file, it needs to be placed in the root directory of your Worklight application, alongside the appl
Once you have done this, create an iPhone or iPad environment for the application if one does not already exist. Then proceed to open the appl
Once you have completed this step, rebuild the application for the iphone/ipad environment, and deploy the project to XCode. Ensure there were no errors in the Worklight console regarding push notifications - this commonly occurs if you have missed a step above.
Once the project is open in Xcode, verify that the application identifier matches the one you specified in the appl
Once this has been confirmed, you will need to ensure that the provisioning settings are correct for the application before you can deploy to your device. To achieve this, you will need to generate a provisioning profile for the app. Head back over to the Apple Provisioning Portal, and this time go to the "Provisioning" section. Choose to create a new development provisioning profile. Associate it with your developer certificate, and select the application you created earlier on from the drop down list. In the list below, select all devices that you would like to deploy this application to.
After completing this, download the resulting provisioning profile. Drag the profile onto the XCode icon in the Dock to add it to XCode. Now you can ensure that the correct provisioning profile is set within XCode. Go to the build settings tab, and search for "code sign". Verify that the selected code signing identity matches the provisioning profile you have just installed.
This should be all you need to get things up and running for an Apple device.
Android Set Up
For Android, the process is thankfully a little quicker. Sign up for a cloud messaging account at the Google API Console. Create a project from here, and turn on Google Cloud Messaging for Android.
Now, you will need a couple of pieces of information to enter into Worklight's appl
Both bits of information from here are required in the XML pushSender entry in your application's appl
Trying it out
To test that push notifications are working correctly for iOS and Android, deploy your application to a device, and the included PushAdapter to your Worklight server.
You can use the various buttons in the sample application to query the state of push notifications.
java -jar /pat