在iOS应用程序中使用twilio进行呼叫录制

时间:2017-03-14 18:37:56

标签: ios twilio phone-call recording

我们正在iOS中创建录制应用程序,在该应用程序中,我们希望提供记录呼叫的功能。对于从应用程序到手机的呼叫,我们使用的是twilio iOS SDK。

如何使用twilio iOS SDK记录通话。

我们希望如果用户启用录制到应用程序,那么调用应该得到记录,如果录制关闭则它不应该得到记录。

我们用于管理twiml的后端技术是PHP。

拨打电话的代码我们写了以下代码:      - (无效)呼叫建立:(的NSString *)dialnumber {         NSString * CallerID = [[NSUserDefaults standardUserDefaults] objectForKey:PRPhoneNumber];         self.callViewController.mainText = dialnumber;         [PKTPhone sharedPhone] .callerId = CallerID;         [[PKTPhone sharedPhone] call:dialnumber];     }

///*** PKTPhone class next working***
-(void)call:(NSString *)callee
{
    [self call:callee withParams:nil];
}

- (void)call:(NSString *)callee withParams:(NSDictionary *)params
{

     reciverID = callee;



    if (!(self.phoneDevice && self.capabilityToken)) {
        NSLog(@"Error: You must set PKTPhone's capability token before you make a call");
        return;
    }

    NSMutableDictionary *connectParams = [NSMutableDictionary dictionaryWithDictionary:params];
    if (callee.length)
        connectParams[@"callee"] = callee;
    if (self.callerId.length)
        connectParams[@"callerId"] = self.callerId;

     connectParams[@"recording"] = @true;

    self.activeConnection = [self.phoneDevice connect:connectParams delegate:self];

    if ([self.delegate respondsToSelector:@selector(callStartedWithParams:incoming:)]) {
        dispatch_async(dispatch_get_main_queue(), ^{
            [self.delegate callStartedWithParams:connectParams incoming:NO];
        });
    }
}

这是我们在服务器端用php编写的代码:

$from     = $_REQUEST['From'];
$callee   = $_REQUEST['callee'];
$callerId = $_REQUEST['callerId'];
$digits   = $_REQUEST['Digits'];

$record = (isset($_REQUEST["recording"]) && $_REQUEST["recording"] == true) ? " record='record-from-answer'" : '';
if (isset($digits) && !$callee) {
    $callee = $_REQUEST[$digits];
}


$response = '<?xml version="1.0" encoding="UTF-8"?>
<Response>
<Dial'.$record.' callerId="'.$callerId.'">
<Number url="http://ourserverurl.net/phoneRecorder/twilio/twilio-client-server-master/notification.php">'.$callee.'</Number>
</Dial>
</Response>';

2 个答案:

答案 0 :(得分:0)

Twilio开发者传道者在这里。

您可以使用connectParamsPrevent md-sidenav from being closed using Escape key when opened。您传递的任何参数都将传递给您的PHP应用程序。因此,您可以添加一个参数来表示您是否正在录制,然后生成将要或不会录制的TwiML。

例如:

NSMutableDictionary *connectParams = [NSMutableDictionary dictionaryWithDictionary:params];
    if (callee.length)
        connectParams[@"callee"] = callee;
    if (self.callerId.length)
        connectParams[@"callerId"] = self.callerId;
    if (self.recording)
        connectParams[@"recording"] = @true;

然后在你的PHP中:

<?php 

$recording = isset($_REQUEST["recording"]);

$response = "<Response>"
$response .= "<Dial";
if ($recording) {
  $response .= " record='record-from-answer'";
}
$response .= "><Number>+15551234567</Number></Dial></Response>";

header("Content-Type: text/xml");
echo $response;

当然,您可能也在设置其他值,这是获取录制参数和pass parameters to the TwiML application的示例。

答案 1 :(得分:0)

Twilio客户支持。

我没有在您的网络应用的HTTP请求中看到参数“录制”。这意味着它不是由iOS应用程序发送的。

- Rob