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
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:
|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.|
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.
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
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
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:
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.
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:
This will generate a new file called
ChatQuickstart.xcworkspace, as with all
Cocoapods projects. Open this file from now on to use the project:
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.
The mobile apps are hard-coded to work with a PHP server running
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
Once the app loads in the simulator, you should see a UI like this one:
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
If you'd like, you can follow along and watch this application get built in a fast three minute code walkthrough.
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.