This is the last section of a four-part tutorial on setting up a mobile backend as a service on Amazon and setting up iOS and Android client applications to enable push notifications. In this section we’ll explain how to run the backend LoopBack application, register the client applications & devices with LoopBack and send PUSH notifications.

If you haven’t done so already, please go to Part One to setup your backend LoopBack application server on Amazon. To setup and create an Android app to receive push notifications go to Part Two. To setup and create an iOS app to receive push notifications go to Part Three.

Run the backend sever

  1. Make sure you have followed the steps in Part One to create your backend application and you have setup the credentials and api keys for your iOS and android applications.

  2. Run the application as node app.js. If the app runs successfully, you should see this:

[ec2-user@ip-10-252-201-3 push]$ node app.js
connect.multipart() will be removed in connect 3.0
visit https://github.com/senchalabs/connect/wiki/Connect-3.0 for alternatives
connect.limit() will be removed in connect 3.0
Browse your REST API at http://0.0.0.0:3000/explorer
LoopBack server listening @ http://0.0.0.0:3000/
Registering a new Application...
Application id: "loopback-push-notification-app"
  1. You can access the swagger REST API explorer which comes with the LoopBack app at:

http://<server_IP_address>:3000/explorerScreen Shot 2014-05-14 at 3.35.53 PM

Receive Push Notifications for Android Client application

  1. Make sure you have created and setup your Android client application by following steps in Part Two.

  2. Set up the REST Adaptor in: src/com/google/android/gcm/demo/app/DemoApplication.java to your server’s IP address.

  3. Click the green “Run” button in the toolbar to run the application. Run it as an Android application. You will be prompted to select the target on which to run the application. Select the AVD you created earlier in Part Two.

  4. Register your application with LoopBack:

  • Since you have set your gcmServerApiKey and appName in config.js, your application will be registered with LoopBack when you run the server.
  • You can verify this using this GET request: /api/applications.
  • You can registered any application using this POST request: /api/applications.
  1. Register your device:
  • If the AVD launches and the app gets installed successfully, the device will be registered with the backend and you should be able to verify the installation using GET request /api/installations.
  • You should also be able to see the GCM application on your android emulator. You will need the “id” from the to send the push notification to the device. You can also get the id from the /api/installations

Screen Shot 2014-05-13 at 4.34.49 PM

  1. To send a Push Notification:
curl -X POST http://ec2-54-184-36-164.us-west-2.compute.amazonaws.com:3000/notify/installation_id
OK
  • You should receive a notification on your emulator and it should look somewhat like this:

Screen Shot 2014-05-13 at 4.43.31 PM

Receive Push Notifications for iOS Client application

  1. Make sure you have created and setup your Android client application by following steps in Part Three.

  2. Make sure you have set the RootPath in apnagent/Settings.plist set to your server’s IP address.

  3. Your registered device should be connected to your computer.

  4. Register your application with LoopBack:
    • Register your application using this POST request to /api/applications.
    • You can verify that the app is registered using this GET request to /api/applications.
    • You need the “id” from the response to identify the client application. In your client app, edit Settings.plist and set AppId to the ID from the previous step.
  5. Run your XCode application and remember to connect your registered device. Select your device while running the app.

  6. Register your device:
    • If the app runs successfully, the iOS device will be registered with the backend and you should be able to verify the installation using GET request /api/installations.
    • You should also be able to see the apnagent application on your phone. Click on Register Device and you should get an alert with the registration number.

To send a Push Notification using REST API:

curl -X POST http://ec2-54-184-36-164.us-west-2.compute.amazonaws.com:3000/notify/device_registration_id
OK

You should receive a notification on your device and it should look somewhat like this:

You can get the full example with the server and client applications on GitHub.

What’s next?