通过使用Twilio提供的示例视频通话应用程序之一(VideoCallKitQuickStart),我尝试通过向应用程序发送VoIP通知来触发来电。但该应用程序不会触发来电。我还尝试在发送VoIP通知时保持应用程序打开状态,并且应用程序崩溃,通过抛出以下异常
NSInvalidArgumentException: Try to 插入非属性列表对象"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)
}
}
发布延迟的答案,但可能对某人有所帮助。
按照我处理语音来电的代码。
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
完成本教程,它将起作用。
Twilio开发者布道者在这里。
我对iOS不是特别好,但是快速浏览一下文档,PKPushRegistryDelegate
看起来您的pushRegistry
函数定义不正确。
它应该是
func pushRegistry(_ registry: PKPushRegistry,
didReceiveIncomingPushWith payload: PKPushPayload,
forType type: PKPushType)
也就是说,didReceiveIncomingPushWith
而不是didReceiveIncomingPushWithPayload
.
或者,这与您将forType
投给String
这一事实有关吗?
Swift 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 可以将传入呼叫通知应用程序