Level up your Twilio API skills in TwilioQuest, an educational game for Mac, Windows, and Linux. Download Now

Menu

Expand
Rate this page:

Thanks for rating this page!

We are always striving to improve our documentation quality, and your feedback is valuable to us. How could this documentation serve you better?

Configuring iOS Push Notifications

In this guide, we'll go through all the necessary steps to get your Apple push credentials configured with Twilio Notifications. The end result is a Twilio Credential which you can then use to receive notifications in your iOS app. Let's get started!

Actions

Step 1 - Setup an App ID

Log into your Apple development account and click on App IDs under the identifiers section. This will show a list of App IDs.

Option 1- Existing App ID

If your App ID is already on this list, click on it and a list of app services will popup.

  1. Click the edit button that pops up
  2. Check the 'Push Notifications' option.
  3. There will be an option to create a Development or Production Certificate. Don't worry about this right now, just click the done button.

Watch an explainer video

Option 2- New App ID

If your App ID isn't on this list, click the "+" symbol to add a new App ID.

  1. Give your app a description as you see fit.
  2. Give it an Explicit App ID that matches the bundle identifier in Xcode.
  3. Under App Services check Push Notifications
  4. Click Continue.
  5. Click Submit to create your new App ID.

Watch an explainer video

Step 2 - Create a Certificate

Now we'll want to create a push notification certificate. This will enable your app to receive notifications. You can either make a development certificate or a production certificate. For this guide, we'll make a development certificate. We recommend you use Xcode managed certificates with Xcode 8.

Option 1 - Xcode Managed Certificates

  1. In your Xcode project, go to the General pane of the target for your iOS application:

2. In the Signing section, check “Automatically manage signing”:

Automatic signing with Xcode

3. If you are using the Quickstart app and see a provisioning error message you may need to rename the bundle id to a unique identifier.

Bundle identifier error

To do so, go to https://developer.apple.com/account/ios/identifier/bundle/create and give the bundle a new name. Then, enter your new identifier in the Identity section of the General pane:

Unique bundle identifier

4. Go to the capabilities tab in Xcode and make sure that Push Notifications are enabled:

Enable push notifications

5. You can verify that your certificates have been created in a few different ways:

a. Via Apple developer portal:

1. Sign in to the Apple developer portal and click on Certificates, IDs & Profile

2. In the Certificates section of the sidebar, select Development or Production depending on the type of certificate you want to verify.

b. Make sure your certificate is stored in your keychain:

1. Locally, go to keychain access and select “Certificates” in the left sidebar. Search for ‘iPhone’ to filter for iPhone certificates.

2. Double-check that your certificate has a disclosure triangle next to it, indicating the existence of your private key in the keychain

6. Congrats! You just created an Apple Development iOS Push Services certificate. If you run into problems during this process, see this guide from Apple.

Option 2 - Manually Create a Certificate

While we recommend you use Xcode managed certificates for your application, you may also choose to manually create your certificate.

  1. Hit the '+' icon in the top right corner.
  2. Under Development, select 'Apple Push Notification service SSL (Sandbox)'.
  3. Click 'Continue'
  4. Select the App ID you previously created in the textbox.
  5. Click 'Continue' again
  6. It will prompt you to create a Certificate Signing Request, with instructions on how to do it. Create one.
  7. Once you've created a CSR, click 'Continue'.
  8. Upload it.
  9. Click 'Generate' to generate your certificate.

Watch an explainer video

Congrats! You just created an Apple Development iOS Push Services certificate. Now you can download it and double click on it locally to add it to your Keychain access.

Step 3 - Create a Credential for Twilio

In Keychain Access, go to the 'My Certificates' Category in the lefthand sidebar.

  1. Right-click your new certificate. It should be labeled "Apple Development iOS Push Services".
  2. Choose "Export"
  3. Save it as cred.p12. (Leave the password blank)

Watch an explainer video

This is your credential file. We're going to extract your certificate key and private key from this file. We need these 2 keys to create a Twilio Credential.

Create a Certificate Key

Run the following command in terminal

openssl pkcs12 -in cred.p12 -nokeys -out cert.pem -nodes

Create a Private Key

Run the following command in terminal

openssl pkcs12 -in cred.p12 -nocerts -out key.pem -nodes

Then this command to process the RSA key

openssl rsa -in key.pem -out key.pem

Then you can paste your credentials into the web console to upload them.

Strip anything outside of "-----BEGIN CERTIFICATE-----" and "-----END CERTIFICATE-----" boundaries and outside of "-----BEGIN RSA PRIVATE KEY-----" and "-----END RSA PRIVATE KEY-----" boundaries before pasting them. Check the 'Sandbox' button if you made a development certificate. Sandbox is synonymous with development mode.

Create APNS Credentials

After you've pasted them in, click save. If everything went well, you'll see a SID appear on the new page. Copy it to your clipboard, you will need it in the next step. Congrats, you just made a Twilio Push Credential!

Configure your Twilio Service to use your APNS credentials

Twilio allows you to build multiple applications in a single account. To separate those applications you need to create Service instances that hold all the data and configuration for your application.

Specifically you need to configure your Service instance to use the Credential that contains your APNS certificate and private key. You can do that using the Services page in the Twilio console. You will need to update your Service with the APNS credential SID.

Configure APNS Credential SID

If you are just getting started, set up this APN credential first, then create your Service first by clicking the red plus button on the services console page.

You are ready to go. Check out the iOS Quickstart to start sending notifications.

Rate this page:

Need some help?

We all do sometimes; code is hard. Get help now from our support team, or lean on the wisdom of the crowd browsing the Twilio tag on Stack Overflow.