我们正在iOS中创建一个录制应用程序,在该应用中,我们希望提供一个功能来录制呼叫。对于从应用程序到电话的电话,我们正在使用Twilio iOS SDK。
如何使用Twilio IOS SDK记录呼叫。
我们希望,如果用户启用录制到应用程序中,则应呼叫获取记录,如果记录已关闭,则不应获取记录。
我们用于管理TWIML的后端技术是php。
用于拨打电话的代码,我们写了一个以下代码: - (void)callSetup :( nsstring*)dialNumber { NSString *CallerId = [[[NSUSERDEFAULTS StandarduserDefaults] ObjectForKey:prphoneNumber]; self.callviewController.maintext = DialNumber; [pktphone sharedphone] .callerid = callerid; [[PKTPHONE共享手机]致电: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>';
twilio开发人员在这里。
您可以使用connectParams
将参数传递到TWIML应用程序。您传递的任何参数都将传递给您的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;
当然,您也可能正在设置其他值,这是获取录制参数并与Twiml一起记录呼叫的一个示例。
Twilio客户支持。
我没有在您的Web应用程序的HTTP请求中看到参数"录制"。这意味着它不是由iOS应用发送的。
- Rob