我正在开发iOS应用程序,我正在使用Twilio SDK来管理通过设备进行的客户端调用。为了实现这一点,我使用的是我在Xcode中成功导入的hello monkey demo应用程序。 初始设置后,我能够成功建立连接,但接收委托不再有效。我已经完成了完整的twilio文档,但没有成功。请尽快建议任何替代方案或解决方案。 这是我的Hello Monkey示例项目代码
- (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);
}
答案 0 :(得分:0)
你是否将代表设置为自己?
_device = [[TCDevice alloc] initWithCapabilityToken:capabilityToken delegate:self];
答案 1 :(得分:0)
Twilio福音传教士在这里。
从你所包含的代码中可以看出它有点难以辨别,这看起来对我来说是正确的。
以下是一些要检查的事项:
您是否在界面上添加了TCDeviceDelegate作为协议:
@interface FooViewController() <TCDeviceDelegate>
您确定将正确的客户名称传递给connect方法,并且从TwiML应用程序语音请求URL返回的TwiML是否正确包含该名称?
您可以通过查看Twilio Monitor来查看这一点,看看Twilio在检索或解析您的TwiML时是否记录了任何错误。你也可以检查你的Twilio call logs,看看Twilio说入站和出站呼叫的结果是什么。
希望有所帮助。