2017-03-14 95 views
1

我们正在iOS中创建一个录音应用程序,在该应用程序中,我们希望提供录制电话的功能。对于从应用程序到手机的呼叫,我们使用twilio iOS SDK。在iOS应用程序中使用twilio拨打电话录音

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

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

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

代码以便进行呼叫,我们已经写了以下代码: - (无效)呼叫建立:(的NSString *)dialnumber { 的NSString *来电= [[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>'; 

回答

0

Twilio开发者传道这里。

您可以使用您的connectParamspass parameters to the TwiML application。您传递的任何参数都将传递给您的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; 

当然,你可能设置其他值太大,这让记录参数和using it with TwiML to record the call的一个例子。

+0

我们已经写了相同的代码在PHP我们的服务器端,但我们没有得到我们的PHP代码记录PARAM。在iOS端,我们编写了相同的代码并发起了呼叫。除了您提供的解决方案中提及的其他设置是否还有其他设置? –

+0

我们正在接收callee和callerId,但是在php中没有收到记录参数。 –

+0

你能编辑你的问题并分享使用这些参数进行呼叫的功能吗?为了帮助,我需要多看点。 – philnash

0

Twilio客户支持在这里。

我没有看到HTTP请求中的参数'录制'到您的web应用程序。这意味着它不会被iOS应用发送。

- 罗布