Tutorial: Push notifications sample app

In this tutorial, you'll use a sample app (iOS, Android, or PhoneGap) to send yourself a push notification with the API BaaS push notification API. You'll register with a push notification services (Apple APNs or Google GCM) to create the required security certificate or key, create the required API BaaS notifier to send a message, then modify, compile and run the sample app to see push notifications in action.

Before you begin

Before you can add support for push notifications, be sure that you're set up for the requirements described in Troubleshooting push notifications.

Step 1: Download a sample app

Sample push notification apps are included in the /samples directory of the following platform SDKs and plugins:

To begin this tutorial, download the sample app for the platform of your choice.

A note to PhoneGap developers: PhoneGap requires a plugin to enable push notifications. The plugin is included in the sample apps in the JavaScript SDK. For new PhoneGap applications, download the PhoneGap push plugin.

Step 2: Register with a notification service and generate a certificate/key

To send push notifications you must register your app with the push notification service that corresponds to your app's platform. Once registered, the service will provide you with a certificate or key that you will provide when creating an API BaaS notifier.

For a full walkthrough of how to register an app with a notification service and generate the necessary certificate/key, see Registering with a notification service.

Step 3: Create a notifier

Notifiers are entities that carry your push notifications to a notification service. Once a notification service has verified that your notifier contains valid credentials, it will deliver your push notification to the devices of your app's users.

For information on how to use the admin portal to create a notifier, see Creating notifiers.

Step 4: Configure and run the sample app

In this step, you'll open your sample app of choice in your IDE and configure it. The Android sample app can be run with an emulator, included in the Android Developer Tools. The iOS sample app must be run on an actual iOS device.

The following sections provide platform-specific guidance for setting up and running the samples. However, this content assumes that you understand your development environment well enough to configure and work with projects.

Step 5: Review the data entities created by the sample app

  1. Log in to the admin portal, and select Data in the left navigation pane.

  2. Select any of the following collections to view the entities that were created in them by the push notification sample app:

    • /devices - To see the device that was added.

    • /notifications - To see the notification that was sent.

    • /receipts - To see the receipt generated from the successful push.

Step 6: Send additional push notifications using other API BaaS tools

Send a push notification from the API BaaS Notifications console

On the Send Notification screen. Select your notifier, select All Devices, enter a message, select Now, and click to send it.

Send a push notification directly via the push notifications API

Use the following curl command in a terminal window, replacing your-org, your-app and notifier-name.

curl -X POST "https://<baas_host_name>/your-org/your-app/devices/*/notifications" -d '{"payloads":{"notifier-name":"I just sent another notification! Yea, me!"}}'