Tutorial: Push notifications sample app

Agradecimiento a : http://apigee.com/docs/app-services/content/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.

For an overview of how to set up push notifications, including troubleshooting tips, see Adding push notifications support.

Before you begin

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

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.

To configure and run the Native iOS push notification sample app, do the following:

  1. Open the iOS sample app with XCode by opening its .xcodeproj file.
  2. Make the following changes to /Push Test/AppDelegate.m:
    • orgName: Your Apigee organization.
    • appName: The app in your organization where you created the notifier. (For the sample, make sure it’s “sandbox”.)
    • notifier: Name of the notifier you created. (For the sample, make sure it’s “appledev”.).
  3. Plug your iOS device into your development machine.
  4. In Xcode, select Window > Organizer to open the Xcode Organizer.
  5. Under Devices, select the device you plugged in, then click Add to Member Center. You may be prompted to log in with the Apple ID associated with your Apple Developer account.
  6. If prompted, select a Development Team to use for provisioning. This will be a team you’ve registered at the Apple developer portal.
  7. Log in to the Apple Developer portal and create a provisioning profile that includes the App ID you chose when you registered the sample app with Apple APNs. For more information on how to create a provisioning profile, see “About provisioning profiles” below.
  8. Download the profile and add it into Xcode Organizer, in the Provisioning Profiles group under your plugged-in device.
  9. Close the Organizer.
  10. In Xcode, select the Project Navigator, then select the project root folder.
  11. In the General tab, in the Bundle Identifer box, enter the App ID associated with your provisioning profile.
  12. In the Build Settings tab, under Deployment, for the iOS Deployment Target select the iOS version on your connected device. The version is displayed in the Xcode Organizer.
  13. In the Build Settings tab, under Code Signing, under Code Signing Identity > Debug, select the Apple signing certificate corresponding to your developer identity.
  14. Click Run to launch the sample on your iOS device.
  15. When the “codesign wants to sign using key <Your Name> in your keychain.” dialog is displayed, click Allow.
  16. The project is now built, and the app is installed on your device. The first time you run the push sample app, your device will ask permission to allow push notifications. Tap OK.
  17. In the app, Tap the Push a notification!button to send yourself a push notification.ios push app

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://api.usergrid.com/your-org/your-app/devices/*/notifications" -d '{"payloads":{"notifier-name":"I just sent another notification! Yea, me!"}}'

Deja un comentario