Twilio语音iOS CallKit拨出电话不工作

时间:2016-12-27 11:40:12

标签: twilio

我正在使用https://github.com/twilio/voice-callkit-quickstart-objc

上托管的iOS客户端快速启动项目 服务器上的

我正在使用python(在github项目上推荐)

当我点击"拨打电话"它运作良好我得到了#34;欢迎来到Twilio"语音。太好了!

然后我稍微更改了代码并尝试拨打特定号码。这是修改后的代码

按钮点击事件

- (IBAction)placeCall:(id)sender {
    NSUUID *uuid = [NSUUID UUID];
    NSString *handle = @"Real Number";

    [self performStartCallActionWithUUID:uuid handle:handle];
}

这里是CallKit句柄

- (void)performStartCallActionWithUUID:(NSUUID *)uuid handle:(NSString *)handle {
    if (uuid == nil || handle == nil) {
        return;
    }

    CXHandle *callHandle = [[CXHandle alloc] initWithType:CXHandleTypeGeneric value:handle];
    CXStartCallAction *startCallAction = [[CXStartCallAction alloc] initWithCallUUID:uuid handle:callHandle];
    CXTransaction *transaction = [[CXTransaction alloc] initWithAction:startCallAction];

    [self.callKitCallController requestTransaction:transaction completion:^(NSError *error) {
        if (error) {
            NSLog(@"StartCallAction transaction request failed: %@", [error localizedDescription]);
        } else {
            NSLog(@"StartCallAction transaction request successful");

            CXCallUpdate *callUpdate = [[CXCallUpdate alloc] init];
            callUpdate.remoteHandle = callHandle;
            callUpdate.supportsDTMF = YES;
            callUpdate.supportsHolding = NO;
            callUpdate.supportsGrouping = NO;
            callUpdate.supportsUngrouping = NO;
            callUpdate.hasVideo = NO;

            [self.callKitProvider reportCallWithUUID:uuid updated:callUpdate];
        }
    }];
}

要拨打的号码

- (void)provider:(CXProvider *)provider performStartCallAction:(CXStartCallAction *)action {
    NSLog(@"provider:performStartCallAction:");

    [[VoiceClient sharedInstance] configureAudioSession];

    NSDictionary *toParam = @{@"To": @"+14805058877"};
    //THIS IS WHERE WE NEED TO INSERT CALLING NUMBER
    self.outgoingCall = [[VoiceClient sharedInstance] call:[self fetchAccessToken]
                                                    params:toParam
                                                  delegate:self];

    if (!self.outgoingCall) {
        [action fail];
    } else {
        self.outgoingCall.uuid = action.callUUID;
        [self toggleUIState:NO];
        [self startSpin];

        [action fulfillWithDateStarted:[NSDate date]];
    }
}

无论我在参数值中输入什么,我总是得到"欢迎来到Twilio"味精。我需要知道我是否需要在Python服务器或iOS客户端代码中进行任何更改。请帮忙!

1 个答案:

答案 0 :(得分:0)

Twilio开发者传道者在这里。

您是否正确设置了TwiML application?语音请求URL应指向您的python服务器。我只是问,来自this line in the code的来自Python服务器的消息应该是#34;祝贺你!你已经打了第一个电话!再见。"你说它是#34;欢迎来到Twilio"

一旦你确定设置了指向你的Python应用程序,一旦你进行了第一次出站呼叫,你将收到该消息。现在您需要更新您的Python应用程序以及iOS应用程序。

您正在发送一个参数To,其中包含您尝试拨打的电话号码。您需要更改Python以便它读取该数字并输出TwiML that will dial that number

这应该看起来像这样:

@app.route('/outgoing', methods=['GET', 'POST'])
def outgoing():
  resp = twilio.twiml.Response()
  resp.dial(request.form['To'])
  return str(resp)

让我知道这是否有帮助。