通过使用 Twilio (VideoCallKitQuickStart) 提供的示例视频通话应用程序之一,我试图通过向应用程序发送 VoIP 通知来触发来电。但该应用程序不会触发来电。我还尝试在发送 VoIP 通知时保持应用程序打开并且应用程序崩溃,方法是抛出以下异常
NSInvalidArgumentException: Attempt to
insert non-property list object 'KPushPayload: 0x16e44af0' for key
payload
当收到 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)
}
}
Best Answer-推荐答案 strong>
发布迟到的答案,但它可能对某人有帮助。
按照我处理语音来电的代码。
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 kit的委托(delegate)方法
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/
|