To send push notifications, you will need to first register your app with the push notification service (Apple APNs or Google GCM) that corresponds to your app's platform. Once you've registered, the service will provide you with a certificate or key that you will need when you create an App Services notifier. (See Creating notifiers for more information.)
Push notification services are gateways controlled by platform services (such as Apple and Google). These gateways ensure that push notifications are delivered securely and originate from trusted apps.
To send push notifications to your app on iOS devices, you’ll register the the Apple Push Notification service (APNs). For app on Android, you’ll register with Google Cloud Messaging for Android (GCM).
Before you can send push notifications to your app on iOS devices, you'll need to get set up so that Apple knows you'll be sending notifications. To do that, you'll need to do the following:
- Generate an SSL signing certificate you can use to generate a .p12 certificate.
- Create an Apple App ID through which you can associate push notifications support with your app.
- Generate a .p12 certificate you can use to create an App Services notifier. The certificate will be sent to APNs with push notification requests.
For more information see "How the pieces connect" in Adding push notifications support.
Generating an SSL signing certificate
First, you'll create an SSL signing certificate that you can use to generate a .p12 certificate. To generate an SSL signing certificate, do the following:
- On your development machine, launch the Keychain Access application.
- From the Keychain Access menu, select Certificate Assistant > Request a Certificate From a Certificate Authority.
- Enter a contact email address and a name you will use to sign your apps.
- Select Saved to disk, then click Continue.
- Select Desktop from the Where drop-down, then click Save to download the .certSigningRequest file.
- Click Done once the download has completed.
Creating an App ID
Next, you must create an App ID for your app. The App ID uniquely identifies your app and provides a way for you to configure the app for push notification support. (For more on App IDs, see Creating and Configuring App IDs.)
- Log in to Apple's iOS developer portal.
- In the iOS Apps section, click Identifiers, then select App IDs.
- Click the + icon to create a new App ID, and enter the following:
- App ID Description - Name: A unique name that identifies your app.
- App Services: Select Push Notifications.
- App ID Suffix: Select Explicit App ID, and enter your desired App ID in reverse-domain format. For example, com.apigee.pushapp.
- Click Submit to create the App ID, then click Done. You will be returned to the App IDs page.
Generating a .p12 certificateFinally, you will generate the .p12 certificate using the App ID and signing certificate you created in the previous steps. The .p12 certificate will be sent by App Services to Apple APNs with all push notification requests. A unique .p12 certificate is required for each app. In addition, you should create separate .p12 certificates for development and production versions of your app.
- On the App IDs page, click your new App ID, then click Edit.
- In the Push Notifications section, under Development SSL Certificate, click Create Certificate.
- Click Choose File, select the .certSigningRequest file you saved to your Desktop in the previous section, then click Generate.
- Click Done. You will be returned to the App ID settings window.
- In the Push Notifications section, click Download to save the certificate (aps_development.cer file) to your Desktop.
- Double-click the .cer file to install it in your keychain. The newly installed certificate will appear in your Keychain Access application under My Certificates with a name similar to "Apple Development iOS Push Services: <bundle identifier>".
- Control-click the certificate and select Export.
- Save the certificate to your Desktop as a 'Personal Information Exchange (.p12)' file. (You'll need this file when you create an App Services notifier. For more information, see Creating notifiers.
- In the password dialog, leave the password field blank, then click OK.
- In the next dialog, enter your system password, then click Allow.
To create an app services notifier for sending notifications, you'll need a Google API project and register your app as part of that project. The project's identifier (project number) will become the sender ID your client code will send when registering. Registering your app will give you an API key you'll use to create an app services notifier. (For more information see "How the pieces connect" in Adding push notifications support.)
The following is an abbreviated version of the steps described in the Google documentation on getting started with Google Cloud Messaging.
To generate a project number and API key, do the following:
Go to the Google API developer web site and log in with your Google ID.
Click Create Project, enter a project name and ID, then follow the steps required to verify.
In the left nav, click Overview to view the project number. Note this number for later use in client code.
Click APIs in the left nav area, then click the button to enable Google Cloud Messaging for Android.
In the left nav, under APIs and auth, click Registered apps, then click Register App.
On the Register new application page, enter a name for your mobile app.
For platform, select Android > Accessing APIs directly from Android.
Under Android Identification, enter a package name that will uniquely identify your app.
Get a SHA1 fingerprint value.
The SHA1 fingerprint represents the keystore and key that uniquely identify you (a requirement for working with Google). This tutorial assumes that you're signing in debug mode (you can also use release mode). If you've been debugging your app with Eclipse and the Android SDK build tools, the key has been created for you. You can also use Ant or perhaps a tool of your own. Android documentation describes the process in more detail at Signing Your Applications.
To discover the SHA1 value, follow the steps below.
In a command prompt, use the keytool utility by typing a command with the following syntax (the default password is "android".):
keytool -exportcert -alias androiddebugkey -keystore path-to-debug-or-production-keystore -list -v
For example, for a default Eclipse installation, the command might be the following:
keytool -exportcert -alias androiddebugkey -keystore ~/.android/debug.keystore -list -v
Enter the SHA1 value in the box provided, then click Register.
In the new page, under Android Key, copy the API Key value for use when creating an app services notifier
Keep the API key handy. You'll need it when you create the app services notifier you'll use to request push notifications from GCM. (For more information, see Creating notifiers.)