Rate this page:

iOS Quickstart

This Quickstart demonstrates how to send Push Notifications using Notify and a Twilio Notify sample iOS app.

To complete this guide you will need to have an Apple developer account, run Xcode on your machine, and have iOS Push Notifications configured.

In the console, create a Notify service. Make note of the SID! You will use this later when you start writing code further down.

Notify SMS Quickstart - set up Notify Service Instance

Gather account information

We need to get the necessary information from our Twilio account. Here's what we'll need:

Config Value Description
Service Instance SID A service instance where all the data for our application is stored and scoped. You can create one in the console.

You will also need to create a push credential on the Twilio Console, and then configure it on your Notify service. You can upload your push credentials here. If you haven't set up the Apple Push Notification Service (APNS) for your app, you can do so by following the iOS push notification guide.

Set up Twilio Functions

When using the Notify service, you'll need to be able to register devices to receive notifications, and then send notifications to those devices. To get you going quickly, you can use Twilio Functions.

Functions is Twilio's serverless code execution environment that lets you write Node.js code that can respond to Twilio webhooks or to regular HTTP POST or GET requests.

You can also always write your own server code using any of Twilio's supported server side languages (Node.js, Python, Ruby, C#, Java, or PHP) - check out how to register bindings or how to send a notification in those languages.

The sample mobile app is already set up to communicate with Twilio Functions to register a device for notifications. You just need to create two Functions in your account from a template, and then specify the URL for one of those Twilio Functions in the source code to the app.

To get started with this, create a new Twilio Function on the Twilio Console's Manage Functions page. Choose the Twilio Notify Quickstart template from the list of templates.

Twilio Notify Quickstart Function Template

After choosing the Twilio Notify Quickstart template, you'll be asked for one piece of configuration information - the Notification Service instance SID that you created at the beginning of this quickstart.

Notification Service SID Configuration

After entering that SID as the value, and clicking create, you will see two new Twilio Functions on your Functions page.

The first function is Register Binding - available at the /register-binding path. The quickstart mobile app sends an identity and the device token that it gets from the Apple Push Notification service to this function to create a binding. Notify uses these bindings to map the device that someone is using to their identity when you send a notification.

The second function is Send Notification - this is available at the /send-notification path. The mobile app does not use this function - instead you can use it to send notifications to yourself on the quickstart app.

If you select either function, you can see the Node.js source code, if you are curious to see how these are implemented.

Lastly, copy the URL for the register binding function - you will need that for the iOS app. Each account has a different subdomain for Twilio Functions - for instance, yours might be something like this:

Now that you have the Twilio Functions created, it's time to set up the iOS app!

Set up the Twilio Notify sample iOS app

Next you will need to :
  • Step 1: Get the Twilio Notify sample iOS app
  • Step 2: Configure iOS Push Notifications, if not done yet
  • Step 3: Run the Twilio Notify sample iOS app on a device and have it pointing to the Twilio Functions URL

Step 1: Get the Twilio Notify sample iOS app

We've provided sample applications to help you get running quickly in both Objective-C and Swift.

Download and unzip the version you prefer, and then open it in Xcode:

These applications are available on GitHub (Objective-C, Swift).

Step 2: Configure iOS Push Notifications

If not done yet, follow this guide to configure iOS Push Notifications.

Next, open the notification project's configuration. On the General tab, set the Bundle Identifier to match the one you used to generate the certificate while configuring iOS Push Notifications.

Notify iOS Quickstart - Sample mobile app bundle identifier

To be able to receive Push Notifications, we need to run the Twilio Notify sample iOS app on a device, as Push Notifications do not work on the iOS Simulator.

Step 3: Run Mobile app on a device and have it pointing to your Twilio Functions URL

To have the mobile app, running on your device, talking to your Twilio Functions, replace the server URL at the top of the ViewController file with your Twilio Functions subdomain URL.

Twilio Notify Functions URL

Now build the app to your device. When the app loads, you should see a simple UI where you can enter an identity for the user.

Next we can create a Binding between user Identity and this device.

Create a Binding for iOS Push Notifications (APNS)

Next we need to create a Binding between user Identity and the device running the app. User Identity can be any unique identifier you choose, like a GUID, or a primary key. User identity should not be personally identifiable information (PII), such as a name or an email address.

In the Twilio Console, navigate to the Twilio Notify Quickstart (Register Bindings) Function that you just created, and leave that web page open while you register with the app. That way, you can see logging information from your function.

In the app enter Identity you choose and click the button Register.

Notify iOS Quickstart - Sample mobile app creating a binding

This action creates a Binding which uniquely identifies a user on a certain device, running your application.

If the binding request wasn't successful, you'll see an error message printed in the Twilio Function logs instead. If there was a problem with the iOS app connecting to the Twilio Function, the error message may be printed out to Xcode's console by the iOS app.

Do not use Personally Identifiable Information for Identity

Notify uses Identity as a unique identifier of a user. You should not use directly identifying information (aka personally identifiable information or PII) like a person's name, home address, email or phone number as Identity because the systems that will process this attribute assume it is not directly identifying information.

Now that we have the Binding, we are ready to send our first Push Notification with Notify.

Send a Push Notification to a device running the Twilio Notify sample iOS app

To send a notification, you can use the Twilio Notify Quickstart (Send Notification) Twilio Function you just created.

You can either send an HTTP GET or an HTTP POST request to the function. Typically, you would send a POST request to the function from your application (as you are performing an action, not retrieving information). If you don't have an easy way to POST a request (like Postman or curl), using GET is fine for testing your quickstart app.

For instance, you might make a request like:

Use the identity you used in the app. Because you registered a binding with Twilio, the server will send your device the 'Hello' message as a notification.

You're all set! From here, you can start building your own application.

What's next?

There's much more you can do with Notify. Try our other Quickstarts to send:

Or learn how to:

For more information on the Notify API, check out our REST API docs.

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 by visiting Twilio's Community Forums or browsing the Twilio tag on Stack Overflow.


        Thank you for your feedback!

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

        Sending your feedback...
        🎉 Thank you for your feedback!
        Something went wrong. Please try again.

        Thanks for your feedback!

        Refer us and get $10 in 3 simple steps!

        Step 1

        Get link

        Get a free personal referral link here

        Step 2

        Give $10

        Your user signs up and upgrade using link

        Step 3

        Get $10

        1,250 free SMSes
        OR 1,000 free voice mins
        OR 12,000 chats
        OR more