iOS Quickstart: Making Calls in/out of your App

Time to put it all together... 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 HelloMonkeyViewController.m's -(void)viewDidLoad method, add some conditional-compilation code:

    NSString *name = @"tommy";
    NSString *name = @"jenny";

    NSString *urlString = [NSString stringWithFormat:@"", name];
    NSURL *url = [NSURL URLWithString:urlString];
    NSError *error = nil;
    NSString *token = [NSString stringWithContentsOfURL:url encoding:NSUTF8StringEncoding error:&error];
    if (token == nil) {
        NSLog(@"Error retrieving token: %@", [error localizedDescription]);
    } else {
        _phone = [[TCDevice alloc] initWithCapabilityToken:token delegate:self];

The Python script has some simple call routing rules:

  • If the call is coming from PSTN, the app tells to Twilio to dial Client jenny.
  • Otherwise, the application tells Twilio to dial whatever number is passed in the To parameter: If the To parameter is a PSTN number, it writes that out within the <Number> noun (which then will call a regular phone). If the To parameter is another client name, as indicated by client: prefix, it writes out a <Client> noun, 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 iOS Simulator. Then have one of the platforms call the other (e.g. by typing "client: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! And of course, you can call regular phone numbers as we demonstrated above.

Wrapping up

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. If you want to learn more about how to customize the telephony experience of your application, check out the TwiML documentation.