iOS中的Twilio语音通话问题

时间:2018-09-10 12:11:07

标签: ios swift twilio

我正在处理twilio Voip通话。我遵循了twilio的文档,根据文档,我已经下载了该项目,并按照该说明进行了操作,并根据我在php中的更改了基本URL。现在我正在获取令牌。我正在将该令牌传递给委托方法,但调用无法连接。我也从功能启用了音频通话。但仍然无法正常工作。这是我的twilio语音通话代码,

func callFetchVoiceTokenAPI() {

    let param = [
        "token" : LoginToken!,
        "identity" : myPhoneNumber!
    ] as [String : Any]

    ServerCall.makeCallWitoutFile(fetchVoiceTokenUrl, params: param, type: Method.POST, currentView: self.view) { (response) in

        print(response ?? JSON.null)

        if let json = response {
            if !json.isEmpty {

                let token = json["token"].stringValue
                print(token)
                let success = json["success"].boolValue
                print(success)
                self.placeCall()
               UserDefaults.standard.set(token, forKey: "voiceToken")
               UserDefaults.standard.synchronize()
            }
        }
    }
}
func placeCall(){

    if (self.call != nil && self.call?.state == .connected) {
        self.call?.disconnect()
       // self.toggleUIState(isEnabled: false, showCallControl: false)
    } else {
        let uuid = UUID()
        let handle = "Hello Hamza"
        print(uuid)
        performStartCallAction(uuid: uuid, handle: handle)
    }

}
 // MARK: Call Kit Actions
func performStartCallAction(uuid: UUID, handle: String) {
    let callHandle = CXHandle(type: .generic, value: handle)
    let startCallAction = CXStartCallAction(call: uuid, handle: callHandle)
    let transaction = CXTransaction(action: startCallAction)
    print(callHandle,startCallAction,transaction)
    callKitCallController.request(transaction)  { error in
        if let error = error {
            NSLog("StartCallAction transaction request failed: \(error.localizedDescription)")
            return
        }

        NSLog("StartCallAction transaction request successful")

        let callUpdate = CXCallUpdate()
        callUpdate.remoteHandle = callHandle
        callUpdate.supportsDTMF = true
        callUpdate.supportsHolding = true
        callUpdate.supportsGrouping = false
        callUpdate.supportsUngrouping = false
        callUpdate.hasVideo = false

        self.callKitProvider.reportCall(with: uuid, updated: callUpdate)
    }
}
func performVoiceCall(uuid: UUID, client: String?, completionHandler: @escaping (Bool) -> Swift.Void) {
    let accessToken = UserDefaults.standard.string(forKey: "voiceToken")
    if accessToken != nil  {
        print(accessToken!)
    }else {
        completionHandler(false)
        return
    }

    call = TwilioVoice.call(accessToken!, params: [twimlParamTo : twimlParamTo], uuid:uuid, delegate: self)
    print(call!)
    self.callKitCompletionCallback = completionHandler
}

这是所有代码执行完毕后的结果, enter image description here

0 个答案:

没有答案