簡體   English   中英

使用CallKit和Twilio-Video API觸發VoIP呼叫

[英]Trigger an incoming VoIP call using CallKit and Twilio-Video API

通過使用Twilio提供的示例視頻通話應用程序之一( VideoCallKitQuickStart ),我試圖通過向該應用程序發送VoIP通知來觸發來電。 但是,該應用程序不會觸發來電。 通過拋出以下異常,我還嘗試在發送VoIP通知時保持應用程序處於打開狀態,並且該應用程序崩潰

NSInvalidArgumentException:嘗試為密鑰有效負載插入非屬性列表對象'PKPushPayload:0x16e44af0'

當收到VoIP通知時,是否可以有人幫助我或為我指出如何觸發應用程序中的傳入呼叫的​​正確方向。

下面是我在ViewController.swift文件中的代碼

 func pushRegistry(registry: PKPushRegistry!, didReceiveIncomingPushWithPayload payload: PKPushPayload!, forType type: String!) {
        // Process the received push

        self.reportIncomingCall(uuid: UUID(), roomName: "testRoom", completion: nil)
    } 

func reportIncomingCall(uuid: UUID, roomName: String?, completion: ((NSError?) -> Void)? = nil) {

    let callHandle = CXHandle(type: .generic, value: roomName ?? "")
    let callUpdate = CXCallUpdate()
    callUpdate.remoteHandle = callHandle
    callUpdate.supportsDTMF = false
    callUpdate.supportsHolding = true
    callUpdate.supportsGrouping = false
    callUpdate.supportsUngrouping = false
    callUpdate.hasVideo = true

    callKitProvider.reportNewIncomingCall(with: uuid, update: callUpdate) { error in
        if error == nil {
            NSLog("Incoming call successfully reported.")
        } else {
            NSLog("Failed to report incoming call successfully: \(error?.localizedDescription).")
        }
        completion?(error as? NSError)
    }
}

Twilio開發人員布道者在這里。

我對iOS並不是特別擅長,但是快速瀏覽一下PKPushRegistryDelegate的文檔,看來您的pushRegistry函數定義不正確。

它應該是

func pushRegistry(_ registry: PKPushRegistry, 
    didReceiveIncomingPushWith payload: PKPushPayload, 
    forType type: PKPushType)

也就是說, didReceiveIncomingPushWith而不是didReceiveIncomingPushWithPayload

另外,它是否與將forType強制forTypeString forType

斯威夫特3.0

func pushRegistry(_ registry: PKPushRegistry, didReceiveIncomingPushWith payload: PKPushPayload, forType type: PKPushType) {
    NSLog("pushRegistry:didReceiveIncomingPushWithPayload:forType:")

    if (type == PKPushType.voIP) {
        print(payload.dictionaryPayload)
        VoiceClient.sharedInstance().handleNotification(payload.dictionaryPayload, delegate: self)
    }
}

而且,請不要對負載進行任何更改,除非對其進行修改,以便SDK可以從負載中提取來電信息,以便SDK可以將來電通知給應用程序

發布較晚的答案,但對某人可能有所幫助。

下面的代碼我確實處理了語音來電。

func pushRegistry(_ registry: PKPushRegistry, didReceiveIncomingPushWith payload: PKPushPayload, for type: PKPushType) {
    NSLog("pushRegistry:didReceiveIncomingPushWithPayload:forType:")
    print(payload)
    if (type == PKPushType.voIP) {
        TwilioVoice.handleNotification(payload.dictionaryPayload, delegate: self)

        pushKitPushReceivedWithPayload(payload: payload)
    }
}
func pushRegistry(_ registry: PKPushRegistry, didReceiveIncomingPushWith payload: PKPushPayload, for type: PKPushType, completion: @escaping () -> Void) {
    NSLog("pushRegistry:didReceiveIncomingPushWithPayload:forType:completion:")

    if (type == PKPushType.voIP) {
        TwilioVoice.handleNotification(payload.dictionaryPayload, delegate: self)

        pushKitPushReceivedWithPayload(payload: payload)
    }

    completion()
}

func pushKitPushReceivedWithPayload(payload: PKPushPayload){
    if UIApplication.shared.applicationState != .active{
        let msgType = payload.dictionaryPayload["twi_message_type"] as? String
        if let messageType = msgType{
            if messageType == "twilio.voice.call"{
                fireLocalNotificationForVoiceCall(didStart: true)
            }else if messageType == "twilio.voice.cancel"{
                fireLocalNotificationForVoiceCall(didStart: false)
            }
        }
    }
}

以下是我添加的呼叫工具包的委托方法

extension AppDelegate : TVONotificationDelegate, TVOCallDelegate
{
  func callInviteReceived(_ callInvite: TVOCallInvite) 
  {
   if (callInvite.state == .pending) 
   {
        //code
   } 
   else if (callInvite.state == .canceled) 
   {
        //code
   }
  }
  func handleCallInviteReceived(_ callInvite: TVOCallInvite) 
  {
        //code
  }

  func handleCallInviteCanceled(_ callInvite: TVOCallInvite) 
  {
        //code
  }
}

我遵循了twilio提供的本教程-https: //github.com/twilio/voice-quickstart-swift

完成本教程,它將起作用。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM