To begin, you'll need to set up a server for sending out capability tokens.
We've included a PHP sample file called
auth.php that's in the Server folder
next to the Xcode project that can create tokens. Note that this also makes use
Capability.php from the Twilio PHP helper library.
<?php include "Services/Twilio/Capability.php"; // AccountSid and AuthToken can be found in your account dashboard $accountSid = "ACXXXXXXXXXXXXXXXX"; $authToken = "your_auth_token_here"; // The app outgoing connections will use: $appSid = "APabe7650f654fc34655fc81ae71caa3ff"; // The client name for incoming connections: $clientName = "monkey"; $capability = new Services_Twilio_Capability($accountSid, $authToken); // This allows incoming connections as $clientName: $capability->allowClientIncoming($clientName); // This allows outgoing connections to $appSid with the "From" // parameter being the value of $clientName $capability->allowClientOutgoing($appSid, array(), $clientName); // This returns a token to use with Twilio based on // the account and capabilities defined above $token = $capability->generateToken(); echo $token; ?>
Making a request to this file on a PHP server will output a string that, when given to a
TCDevice, grants it capabilities such as making outgoing calls or allowing incoming calls.
Note that the token generated is valid for 1 hour unless otherwise specified. To specify a different period of time, pass in the number of seconds as an integer parameter to
generateToken() -- for example, for a token that expires after 5 minutes, call
generateToken(300). The maximum allowed lifetime for a token is 24 hours.
To fetch the token, put the
auth.php file and Twilio Helper Library PHP files on your server, and then modify the
$authToken to be values from your Twilio account. To make sure it works, open a web browser and hit the URL (e.g.
http://companyfoo.com/auth.php). Assuming there aren't any issues, you should see a long string of text -- this is a capability token for the user named "monkey" to receive incoming and make outgoing calls.
Now let's walk through making an outgoing call to a phone number. This code can be run either in the iOS Simulator or on your device.