通过使用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)
}
}
答案 0 :(得分:1)
发布较晚的答案,但可能对某人有帮助。
以下是我处理语音来电的代码。
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
阅读本教程,它将起作用。
答案 1 :(得分:0)
Twilio开发者传道者在这里。
我对iOS不是特别擅长,但要快速查看PKPushRegistryDelegate
的文档,看起来您的pushRegistry
函数定义是对的。
应该是
func pushRegistry(_ registry: PKPushRegistry,
didReceiveIncomingPushWith payload: PKPushPayload,
forType type: PKPushType)
即didReceiveIncomingPushWith
而不是didReceiveIncomingPushWithPayload
。
或者,它是否与您将forType
投放到String
这一事实有关?
答案 2 :(得分:0)
Swift 3.0
border-inline-end
请不要对有效负载进行任何更改而不进行修改,以便SDK从有效负载中提取来电信息,以便SDK可以通过来电通知应用程序