Congratulations on making your first audio connection from your iOS device to Twilio!
You should have heard a welcome message but as you probably noticed, you had no way to close the connection as the Hangup button doesn't do anything. So, let's add some functionality to do that.
Since MonkeyPhone is the central object coordinating with the Twilio Client API, let's add a -(void)disconnect method there:
#import <Foundation/Foundation.h>
#import "TCDevice.h"
#import "TCConnection.h"
@interface MonkeyPhone : NSObject
{
@private
TCDevice* _device;
TCConnection* _connection;
}
-(void)connect;
-(void)disconnect;
@end
// … unmodified code omitted for brevity
-(void)connect
{
_connection = [_device connect:nil delegate:nil];
[_connection retain];
}
-(void)disconnect
{
[_connection disconnect];
[_connection release];
_connection = nil;
}
And add code in the HelloMonkeyViewController to call this new method when the hangup button is pressed:
// …
-(IBAction)dialButtonPressed:(id)sender
{
HelloMonkeyAppDelegate* appDelegate = (HelloMonkeyAppDelegate*)[UIApplication sharedApplication].delegate;
MonkeyPhone* phone = appDelegate.phone;
[phone connect];
}
-(IBAction)hangupButtonPressed:(id)sender
{
HelloMonkeyAppDelegate* appDelegate = (HelloMonkeyAppDelegate*)[UIApplication sharedApplication].delegate;
MonkeyPhone* phone = appDelegate.phone;
[phone disconnect];
}
@end
That's everything! Go ahead and make another call. You can now press the hangup button at any time and your connection will close.