Ready to add voice communication to your iOS apps with Twilio Client? This quickstart gets you all set up and going - there's a server app you'll need to run (your choice of language), and an example iOS app (Swift or Objective-C) to show you the ropes! You'll need both pieces of the puzzle to get started.
The first thing we need to do is grab all the necessary information from our Twilio account. To set up our back-end for Twilio Client, we will need four values from our account:
|Account SID||Your primary Twilio account identifier - find this in the console here.|
|Auth Token||Used to authenticate - just like the above, you'll find this here.|
|TwiML App SID||The TwiML application with a voice URL configured to access your server running this app - create one in the console here. Also, you will need to configure the Voice "REQUEST URL" on the TwiML app once you've got your server up and running.|
|Twilio Phone #||A Twilio phone number in E.164 format - you can get one here|
Choose a download package for your server-side language of choice. If you're primarily a mobile app developer and don't have a strong preference, Node.js or Ruby will probably get you up and running the fastest.
Follow the instructions in the README for each starter application to configure and run it on your machine, using the four values we created above:
Once you've got your server up and running, you will need to host it somewhere Twilio can access it. You can publish your app to a web hosting provider, or you can run it locally and use ngrok to create a tunnel to your development machine with a publicly accessible URL. See the README above for the specific ngrok instructions for your preferred platform.
Now, configure the Voice "REQUEST URL" on your TwiML App to hit the voice URL on your server. Again, see the README above for platform-specific instructions.
This is where the fun begins! When you visit the homepage of the starter application, you should see a page which looks like this:
You have been assigned a random client name and are ready to make phone calls. You can type in a phone number to make a call, or you can type in the client name of another user. Try opening the web application in another browser window and call yourself. Echo...echo...echo.
While all of this is great (and we can use it to test the iOS app) - you're a mobile app developer, right? Let's get straight to some iOS code!
You will need XCode to run the starter iOS application, but you won't need your own iPhone or iPad - this app will work on the simulator just fine! Of course, running on your own device is more fun.
We do have two choices of language - either Swift or Objective-C! If you're just getting started with iOS application development, we recommend starting with Swift.
You can also download the SDK and manually install the libraries and headers into your project.
One more thing you'll need to do before you run the application - you'll need to change the URL for capability tokens that the app uses to authorize itself with Twilio. This URL is going to be related to the server application you installed above - if you haven't done that step, and deployed the application to a web host or created an external URL with ngrok, go ahead and do that now.
After that, go ahead and find this constant, TOKEN_URL, in DialViewController.swift (or DialViewController.m), and change it to your token location.
let TOKEN_URL = "https://asdf456.ngrok.io/token"
We've kept the iOS quickstart app pretty simple! All of the code you'll be interested in is in the DialViewController class. After the view controller loads, we retrieve the capability token from your server, initialize a Twilio Client Device (TCDevice), and then wait for incoming connections (for instance, from the web app).
You can also connect to either a named client (like the web app), or a phone number (like your own)! Go ahead and call yourself from your app, it'll be fun!