iOS Quickstart

In this guide, we will get you up and running quickly with a sample application you can build on as you learn more about Programmable Chat. Sound like a plan? Then let's get cracking!

Table Of Contents

Gather account information

The first thing we need to do is grab all the necessary information from our Twilio account. To set up our back-end for Chat, we will need four values from our account:

Config Values Description
Service Instance SID A service instance where all the data for our application is stored and scoped. Generate one in the console here.
Account SID Your primary Twilio account identifier - find this in the console here.
API Key Used to authenticate - generate one here.
API Secret Used to authenticate - just like the above, you'll get one here.

Set up the server app

A Chat application has two pieces - a client (our iOS app) and a server. You can learn more about what the server app does by going through this guide. For now, let's just get a simple server running so we can use it to power our iOS application.

Download server app for PHP

If you prefer, there are backend apps available for other server-side languages.

Unzip the app you just downloaded, and navigate to that folder in a Terminal window on your Mac. Your Mac should already have PHP installed, we just need to configure and run the app. In the terminal, create a file to hold the four credentials we retrieved from the steps above:

cp config.example.php config.php

Open config.php and enter in your account credentials inside the single quotes for the appropriate variables. Now we're ready to start the server - again in your terminal, run:

php -S localhost:8000

To confirm everything is set up correctly, visit http://localhost:8000 in a web browser. You should be assigned a random username, and be able to enter chat messages in a simple UI that looks like this:

quick start app screenshot

Feel free to open this app up in a few browser windows and chat with yourself! You might also find this browser app useful when testing your iOS app, giving you an easy second screen to send chat messages. Leave this server app running in the Terminal so that your iOS app running in the simulator can talk to it.

Now that our server is set up, let's get the starter iOS app up and running.

Download and explore the mobile app

To get going quickly, there are starter apps built as stand-alone Xcode 8 projects written in both Swift and Objective-C. Download one of them now:

Both applications are built using the Cocoapods package manager and are available on GitHub (Objective-C, Swift). With Cocoapods installed, download and unzip your preferred application. Go to the application's directory in the Terminal, and install dependencies with:

pod install

This will generate a new file called ChatQuickstart.xcworkspace, as with all Cocoapods projects. Open this file from now on to use the project:

open ChatQuickstart.xcworkspace

Your dependencies should all be installed and ready to rock - if you shut down the PHP server from the step above, make sure to restart it before running your app in the simulator.

Important Note About Running on Device

The mobile apps are hard-coded to work with a PHP server running on http://localhost:8000, a URL which will only be visible while running on the simulator on your Mac. To test on a device, you'll need to replace this URL in ViewController with a public URL for the token server. Consider checking out ngrok to expose your local server on the public Internet.

Once the app loads in the simulator, you should see a UI like this one:

quick start app screenshot

Start sending yourself a few messages - they should start appearing both in a UITableView in the starter app, and in your browser as well if you kept that window open.

Watch this app get built

If you'd like, you can follow along and watch this application get built in a fast three minute code walkthrough.

Now You're Ready

You're all set! From here, you can start building your own application. For guidance on integrating the iOS SDK into your existing project, head over to our install guide. If you'd like to learn more about how Programmable Chat works, you might want to dive into our user identity guide, which talks about the relationship between the mobile app and the server.

Next: Managing User Identity and Access Tokens »