Setting Up APNS for Push Notifications
Push notifications for iOS apps are sent using Apple Push Notification service (APNs). Before you can send push notifications to iOS devices, you must create an app ID on the Apple Developer portal, and you must create the required certificates.
This section describes how to use the Apple Developer portal to obtain iOS and APNs credentials. These credentials enable you to create an iOS project that can receive push notifications.
You do not need an existing iOS app to complete the steps in this section. After you complete these steps, see the main Push Notifications API Guide for instructions on setting up an app to use AWS Pinpoint to receive push notifications.
After completing the steps in this section, you will have the following items in your Apple Developer account:
- An app ID.
- An SSL certificate, which authorizes you to send push notifications to your app through APNs.
- A registration for your test device, such as an iPhone, with your Apple Developer account.
- An iOS distribution certificate, which enables you to install your app on your test device.
- A provisioning profile, which allows your app to run on your test device.
Before you begin, you must have an account with the Apple Developer Program as an individual or as part of an organization, and you must have agent or admin privileges in that account.
The steps in this tutorial are based on the following versions of Mac OS software:
- OS X El Capitan version 10.11.6
- Xcode version 8.1
Topics
- Step 1: Create an App ID
- Step 2: Create an APNs SSL Certificate
- Step 3: Register a Test Device
- Step 4: Create an iOS Distribution Certificate
- Step 5: Create a Provisioning Profile
Step 1: Create an App ID
Create an app ID to identify your app in the Apple Developer portal. You need this ID when you create an SSL certificate for sending push notifications, when you create an iOS distribution certificate, and when you create a provisioning profile.
If you already have an ID assigned to your app, you can skip this step. You can use an existing app ID provided it doesn’t contain a wildcard character (“*”).
To assign an App ID to your app
-
Sign in to your Apple Developer account at https://developer.apple.com/membercenter/index.action.
-
Choose Certificates, Identifiers & Profiles.
-
In the Identifiers section, choose App IDs.
-
In the iOS App IDs pane, choose the Add button (+).
-
In the Registering an App ID pane, for Name, type a custom name for your app ID that makes it easy to recognize later.
-
Choose the default selection for an App ID Prefix.
-
For App ID Suffix, select Explicit App ID, and type a bundle ID for your app. If you already have an app, use the bundle ID assigned to it. You can find this ID in the app project in Xcode on your Mac. Otherwise, take note of the bundle ID because you will assign it to your app in Xcode later.
-
Under App Services select Push Notifications.
-
Choose Continue. In the Confirm your App ID pane, check that all values were entered correctly. The identifier should match your app ID and bundle ID.
-
Choose Register to register the new app ID.
Step 2: Create an APNs SSL Certificate
Create an APNs SSL certificate so that you can deliver push notifications to your app through APNs. You will create and download the certificate from your Apple Developer account. Then, you will install the certificate in Keychain Access and export it as a .p12
file.
If you already have an SSL certificate for your app, you can skip this step.
To create an SSL certificate for push notifications
-
Sign in to your Apple Developer account at https://developer.apple.com/membercenter/index.action.
-
Choose Certificates, Identifiers & Profiles.
-
In the Identifiers section, choose App IDs.
-
From the list of iOS app IDs, select the app ID that you created in Step 1: Create an App ID.
-
Choose Edit.
-
Under Push Notifications, in the Production SSL Certificate section, choose Create Certificate….
-
In the About Creating a Certificate Signing Request (CSR) pane, follow the instructions for creating a Certificate Signing Request (CSR) file. You use the Keychain Access application on your Mac to create the request and save it on your local disk. When you are done, choose Continue.
-
In the Generate your certificate pane, choose Choose File…, and then select the CSR file you created.
-
Choose Continue.
-
When the certificate is ready, choose Download to save the certificate to your computer.
-
Double-click the downloaded certificate to install it to the Keychain on your Mac.
-
On your Mac, start the Keychain Access application.
-
In My Certificates, find the certificate you just added. The certificate is named “Apple Push Services:
com.my.app.id
”, wherecom.my.app.id
is the app ID for which the certificate was created. -
Context-select the push certificate and then select Export… from the context menu to export a file containing the certificate.
-
Type a name for the certificate that is easy to recognize and save it to your computer. Do not provide an export password when prompted. You need to upload this certificate when creating your app in AWS Mobile Hub.
Step 3: Register a Test Device
Register a test device with your Apple Developer account so that you can test your app on that device. Later, you associate this test device with your provisioning profile, which allows your app to launch on your device.
If you already have a registered device, you can skip this step.
To add a device
-
Sign in to your Apple Developer account at https://developer.apple.com/membercenter/index.action.
-
Choose Certificates, Identifiers & Profiles.
-
In the Devices section, choose the type of device that you want to add, such as iPhone.
-
Choose the Add button (+).
-
In the Register Device section, for Name, type a name that is easy to recognize later.
-
For UDID, type the unique device ID. For an iPhone, you can find the UDID by completing the following steps:
-
Connect your iPhone to your Mac with a USB cable.
-
Open the iTunes app.
-
In the top left corner of the iTunes window, a button with an iPhone icon is shown. Choose this button. iTunes displays the summary page for your iPhone.
-
In the top box, the summary page provides your iPhone’s Capacity, Phone Number, and Serial Number. Click Serial Number, and the value changes to UDID.
-
Context-select your UDID, and choose Copy.
-
Paste your UDID into the UDID field in the Apple Developer website.
-
-
Choose Continue.
-
On the Review and register pane, verify the details for your device, and choose Register. Your device name and identifier are added to the list of devices.
Step 4: Create an iOS Distribution Certificate
An iOS distribution certificate enables you to install your app on a test device and deliver push notifications to that device. You specify your iOS distribution certificate later when you create a provisioning profile for your app.
If you already have an iOS distribution certificate, you can skip this step.
To create an iOS distribution certificate
-
On the Certificates, Identifiers & Profiles page of your Apple Developer account, in the Certificates section, choose Production.
-
In the iOS Certificates (Production) pane, choose the Add button (+). The Add iOS Certificate pane opens.
-
In the Production section, select App Store and Ad Hoc, and then choose Continue.
-
On the About Creating a Certificate Signing Request (CSR) page, choose Continue.
-
In the About Creating a Certificate Signing Request (CSR) pane, follow the instructions for creating a Certificate Signing Request (CSR) file. You use the Keychain Access application on your Mac to create the request and save it on your local disk. When you are done, choose Continue.
-
In the Generate your certificate pane, choose Choose File…, and then select the CSR file you created.
-
Choose Continue.
-
When the certificate is ready, choose Download to save the certificate to your computer.
-
Double-click the downloaded certificate to install it in Keychain on your Mac.
Step 5: Create a Provisioning Profile
A provisioning profile allows your app to run on your test device. You create and download a provisioning profile from your Apple Developer account and then install the provisioning profile in Xcode.
To create a provisioning profile
-
Sign in to your Apple Developer account at https://developer.apple.com/membercenter/index.action.
-
Choose Certificates, Identifiers & Profiles.
-
In the Provisioning Profiles section, choose Distribution.
-
In the iOS Provisioning Profiles (Distribution) pane, choose the Add button (+). The Add iOS Provisioning Profiles (Distribution) pane is shown.
-
In the Distribution section, select Ad Hoc, and then choose Continue.
-
For App ID, select the app ID you created for your app, and then choose Continue.
-
Select your iOS Development certificate and then choose Continue.
-
For Select devices, select the device that you registered for testing, and choose Continue.
-
Type a name for this provisioning profile, such as
ApnsDistributionProfile
, and choose Continue. -
Select Download to download the generated provisioning profile.
-
Install the provisioning profile by double-clicking the downloaded file. The Xcode app opens in response.
-
To verify that the provisioning profile is installed, check the list of installed provisioning profiles in Xcode by doing the following:
-
In the Xcode menu bar, choose Xcode and then choose Preferences.
-
In the preferences window, choose Accounts.
-
In the Accounts tab, select your Apple ID, and then choose View Details.
-
Check that your provisioning profile is listed in the Provisioning Profiles section.
-