通过使用Twilio提供的示例视频通话应用程序之一(VideoCallKitQuickStart),我试图通过向该应用程序发送VoIP通知来触发来电。但是该应用不会触发来电。通过抛出以下异常,我还尝试在发送VoIP通知时保持打开状态,并且应用程序崩溃

NSInvalidArgumentException:尝试执行
为密钥插入非属性列表对象'PKPushPayload:0x16e44af0'
有效载荷

当收到VoIP通知时,是否可以有人帮助我或为我指明如何触发应用程序中的传入 call 的​​正确方向。

下面是我在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)
    }
}

最佳答案

发布较晚的答案,但对某人可能有所帮助。

下面的代码我做了处理语音来电。

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)
            }
        }
    }
}

以下是我添加的 call 工具包的委托方法
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

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

关于ios - 使用CallKit和Twilio-Video API触发VoIP调用,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/41498841/

10-12 14:31
查看更多