Menu
Amazon Simple Notification Service
Developer Guide (API Version 2010-03-31)

Getting Started with Apple Push Notification Service

Apple Push Notification Service (APNS) is a service that enables you to send push notification messages to iOS and OS X apps. This section describes how to obtain the APNS prerequisites and send a push notification message using Amazon SNS and APNS.

APNS Prerequisites

To send push notifications to mobile devices using Amazon SNS and APNS, you need to obtain the following:

  • iOS app registered with APNS

  • APNS SSL certificate

  • App private key

  • Device token

If you already have these prerequisites, you can send a push notification message to an iOS app using either the Amazon SNS console or you can use the Amazon SNS API. For more information about using the Amazon SNS console, see Using Amazon SNS Mobile Push. For more information about using the Amazon SNS API, see Send a push notification message to an iOS app using Amazon SNS and APNS.

Step 1: Create an iOS App

To get started with sending a push notification message to an iOS app, you must have an Apple developer account, created an App ID (application identifier), registered your iOS device, and created an iOS Provisioning Profile. For more information, see the Local and Remote Notification Programming Guide in the iOS Developer Library.

Note

If you do not already have an iOS app registered with APNS, then you can use the sample iOS app provided by AWS as a template to get started. For more information, see Step 5: Obtain a Device Token.

Step 2: Obtain an APNS SSL Certificate

Amazon SNS requires the APNS SSL certificate of the app in the .pem format when using the Amazon SNS API. When using the Amazon SNS console you can upload the certificate in .p12 format and Amazon SNS will convert it to .pem and display it in the console. You use the Keychain Access application on your Mac computer to export the APNS SSL certificate. For more information about the SSL certificate, see Provisioning and Development in the Apple Local and Push Notification Programming Guide.

To download an APNS SSL certificate

  1. On the Apple Developer web site, click Member Center, click Certificates, Identifiers and Profiles, and then click Certificates.

  2. Select the certificate you created for iOS APNS development, click Download, and then save the file, which will have the .cer extension type.

To convert the APNS SSL certificate from .cer format to .pem format

The following steps use the openssl utility.

  • At a command prompt, type the following command. Replace myapnsappcert.cer with the name of the certificate you downloaded from the Apple Developer web site.

    openssl x509 -in myapnsappcert.cer -inform DER -out myapnsappcert.pem

    The newly created .pem file will be used to configure Amazon SNS for sending mobile push notification messages.

Step 3: Obtain the App Private Key

Amazon SNS requires an app private key in the .pem format. You use the Keychain Access application on your Mac computer to export the app private key.

To obtain the app private key

The private key associated with the SSL certificate can be exported from the Keychain Access application on your Mac computer. This is based on the assumption that you have already imported the .cer file you downloaded from the Apple Developer web site into Keychain Access. You can do this either by copying the .cer file into Keychain Access or double-clicking the .cer file.

  1. Open Keychain Access, select Keys, and then highlight your app private key.

  2. Click File, click Export Items..., and then enter a name in the Save As: field.

  3. Accept the default .p12 file format and then click Save.

    The .p12 file will then be converted to .pem file format.

To convert the app private key from .p12 format to .pem format

  • At a command prompt, type the following command. Replace myapnsappprivatekey.p12 with the name of the private key you exported from Keychain Access.

    openssl pkcs12 -in myapnsappprivatekey.p12 -out myapnsappprivatekey.pem -nodes -clcerts

    The newly created .pem file will be used to configure Amazon SNS for sending mobile push notification messages.

Step 4: Verify the Certificate and App Private Key

You can verify the .pem certificate and private key files by using them to connect to APNS.

To verify the certificate and private key by connecting to APNS

  • At a command prompt, type the following command. Replace myapnsappcert.pem and myapnsappprivatekey.pem with the name of your certificate and private key.

    openssl s_client -connect gateway.sandbox.push.apple.com:2195 -cert myapnsappcert.pem -key myapnsappprivatekey.pem

Step 5: Obtain a Device Token

When you register your app with APNS to receive push notification messages, a device token (64-byte hexadecimal value) is generated. The following steps describe how to use the sample iOS app provided by AWS to obtain a device token from APNS. You can use this sample iOS app to help you get started with Amazon SNS push notifications. For more information, see Registering for Remote Notifications in the Apple Local and Push Notification Programming Guide.

To obtain a device token from APNS for your app

  1. Download and unzip the snsmobilepush.zip file.

  2. Navigate to the AppleMobilePushApp folder and then open either the iOS 7 and earlier or iOS 8 folder.

  3. In Xcode, open the AmazonMobilePush.xcodeproj project.

  4. Run the app in Xcode. In the output window, you should see the device token displayed, which is similar to the following:

    Device Token = <examp1e 29z6j5c4 df46f809 505189c4 c83fjcgf 7f6257e9 8542d2jt 3395kj73>

    Note

    Do not include spaces in the device token when submitting it to Amazon SNS.

Next Steps

You should now have the necessary information from APNS (SSL certificate, app private key, and device token) to send push notification messages to your mobile endpoint. You can now send a notification to the iOS app on your device by either using the Amazon SNS console or the Amazon SNS API.