Get Started

Twilio Client for iOS Quickstart Tutorial

Making Calls In and Out of your App

Time to put it all together... using your quick start skills, you've already initiated an outgoing connection, and received an incoming connection. Now, let's call from one client to another!

For this example, we'll make a call between the iOS Simulator and your device.

To do this, we'll need to log in as two different users. We'll change the log in code to register as "tommy" for the app in the iOS Simulator, and "jenny" for the app on your iOS device.

In MonkeyPhone.m's -(id)init method, add some conditional-compilation code:

    if ( self = [super init] )
        NSURL* url = [NSURL URLWithString:@""];
        NSURL* url = [NSURL URLWithString:@""];

// … code omitted
    return self;

Next we'll change the TwiML PHP file to connect your two clients together. So, change the file hello-client-monkey-twiml.php to:

header('Content-type: text/xml');

$number = $_REQUEST["PhoneNumber"];

// put a phone number you've verified with Twilio to use as a caller ID number
$callerId = "XXXXXXXXXX";
    <Dial callerId="<?php echo $callerId ?>">
    <?php if (preg_match("/^[\d\(\)\-\+ ]+$/", $number)) { ?>
        <Number><?php echo $number;?></Number>
    <?php } else { ?>
        <Client><?php echo $number;?></Client>
    <?php } ?>

The above PHP program does checks whether the "PhoneNumber" is only digits and if so, write that out within the <Number> (which will then call a regular phone) otherwise write out <Client> instead, which will try and connect to a named Twilio Client app (a browser or another mobile client).

So now build, install, and run your app on both your iOS device and the iOS Simulator. Then have one of the platforms call the other (e.g. by typing "tommy" into the iOS device's app). Once the connection has been established you should be able to talk between your phone and your laptop!

You can also dial regular phone numbers from your iOS app as long as you replace the $callerId value in the PHP above with a phone number that's verified with your Twilio Account. See the "Verified Numbers" section under the Numbers Tab in your Twilio Account.

That's it for this quickstart. If you want to learn more about the iOS library that we have been using throughout this document, then head over to the iOS API Reference Xcode DocSet included with the SDK or view it online.