Chinese Documentation : Tutorial: push notifications - putting it all together

This is the final part 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. 

Run the backend sever 

  1. Make sure you have followed the steps in part 1 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"
  3. You can access the swagger REST API explorer which comes with the loopback app at http://<server_ip>:3000/explorer:

Receive push notifications for Android client application 

  1. Make sure you have set the rest adaptor in src/com/google/android/gcm/demo/app/DemoApplication.java to your server's IP address. 
  2. 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 2
  3. Register your application with Loopback:
    1. Since you have set your gcmServerApiKey and appName in config.js, your application will be registered with loopback when you run the server. 
    2. You can verify this using this GET request  - /api/applications
    3. You can registered any application using this POST request - /api/applications
  4. Register your device:

    1. 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

    2. 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

  5. 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
  6. The notification received on your emulator should look like this:

Receive push notifications for iOS client application 

  1. Make sure you have set the RootPath in apnagent/Settings.plist set to your server's ip address.
  2. Your phone should be connected to your laptop.
  3. Register your application with loopback - 
    1. Register your application using this POST request - /api/applications
    2. You can verify that the app is registered using this GET request  - /api/applications
    3. 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.
  4. Run your XCode application and remember to connect your registered device. Select your device while running the app.
  5. Register your device -
    1. 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

    2. 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.

  6. 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>
    OK
  7. You should receive a notification on your device and it should look like this: