skip to Main Content

I am working on iOS application where I am using Twilio SDK to manage client calling through device. To implement this i am using hello monkey demo application which i have successfully imported in Xcode.
After initial setup i am able to establish connection successfully but receiving delegate is no longer working. I have gone through complete twilio documentation but no success. Please suggest any alternative or solution ASAP.
Here is my code of Hello Monkey sample project

- (void)viewDidLoad
{

    NSLog(@"CLINT ID-----------------------     %@",name);

    //check out https://github.com/twilio/mobile-quickstart to get a server up quickly
    NSString *urlString = [NSString stringWithFormat:@"https://testdemo786.herokuapp.com/token?client=%@", 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];

    }
}

- (IBAction)dialButtonPressed:(id)sender
{
    NSString *to;
    if ([name isEqualToString:@"jenny"]) {
        to=@"client:tommy";
    }
    else
    {
        to=@"client:jenny";
    }


    to=@"4nmf5j";
    NSLog(@"TO---------------------%@",to);
    NSDictionary *params = @{@"To": to};

    _connection = [_phone connect:params delegate:nil];
}

- (IBAction)hangupButtonPressed:(id)sender
{
    [_connection disconnect];
}

- (void)device:(TCDevice *)device didReceiveIncomingConnection:(TCConnection *)connection
{
    NSLog(@"Incoming connection from: %@", [connection parameters][@"From"]);
    if (device.state == TCDeviceStateBusy) {
        [connection reject];
    } else {
        [connection accept];
        _connection = connection;
    }
}

-(void)connection:(TCConnection*)connection didFailWithError:  (NSError*)error{

    NSLog(@"Connection failed with error : %@", error);

}

-(void)connectionDidStartConnecting:(TCConnection*)connection{
    NSLog(@"connection started");
}

-(void)connectionDidDisconnect:(TCConnection*)connection{
    NSLog(@"connection disconnected");
}

-(void)connectionDidConnect:(TCConnection*)connection{
    NSLog(@"connected");
}

- (void)deviceDidStartListeningForIncomingConnections:  (TCDevice*)device
{
    NSLog(@"Device: %@ deviceDidStartListeningForIncomingConnections",   device);
}

- (void)device:(TCDevice *)device didStopListeningForIncomingConnections:(NSError *)error
{
    NSLog(@"Device: %@ didStopListeningForIncomingConnections: %@", device, error);
}

2

Answers


  1. did you set the delegate to self?
    _device = [[TCDevice alloc] initWithCapabilityToken:capabilityToken delegate:self];

    Login or Signup to reply.
  2. Twilio evangelist here.

    Its a bit hard to tell from the code you included, which does look correct to me.

    Here are a couple of things to check:

    1. Did you add the TCDeviceDelegate as a protocol on your interface:

      @interface FooViewController() <TCDeviceDelegate>
      
    2. Are you sure you passing the correct client name to the connect method, and that the TwiML being returned from your TwiML Apps Voice Request URL is including that name properly?

      You could check this by looking at the Twilio Monitor to see if Twilio logged any errors when retrieving or parsing your TwiML. You can also check your Twilio call logs to see what Twilio says the outcome of the inbound and outbound call legs were.

    Hope that helps.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search