Free Accounts & Free Advice

Twilio Client for iOS Quickstart Tutorial

Receiving Incoming Calls

Now, that we know how to initiate connections from your app, it's time
for your app to start receiving incoming connections! By the end of
this tutorial, you will be able to call in to your device using the iOS
Simulator (or vice-versa). Hold on tight...

Change your code to pass a client name to your application server when
it starts up. (In a real app, you would pass a username/password
combination from UITextFields, but we'll omit this for simplicity.)

TCDevice announces important events to an object that implements the
TCDeviceDelegate protocol:

-(void)deviceDidStartListeningForIncomingConnections:(TCDevice*)device:
callback for when the device is successfully registered with Twilio.

-(void)device:(TCDevice*)device didStopListeningForIncomingConnections:(NSError*)error:
callback for when the device is no longer listening for incoming
connections due to error or a call to -[TCDevice unlisten].

-(void)device:(TCDevice*)device didReceiveIncomingConnection:(TCConnection*)connection:
callback for when a client receives an incoming connection

Please register the instance of HelloMonkeyViewController to be
TCDevice's delegate during (id)viewDidLoad:

Next, implement
-(void)device:(TCDevice*)device didReceiveIncomingConnection:(TCConnection*)connection
and have it accept the incoming connection when we get the callback.
Note that we can only accept incoming connection when the device is not busy.

For completeness, implement the remaining two delegate methods to print
out various state transitions and any errors (note that
-device:didStopListeningForIncomingConnections: is a required method for the
delegate):

If you compile and run the app, it's now ready to receive incoming
calls! Now we need to
provision a Twilio phone number
and configure the Voice URL to point to your application server: http://{your app's url}/call.

Call your Twilio number and you should be connected to your device (or
iOS Simulator, whichever you're running), which will automatically
answer the call! Start talkin'.