ios - 使用 CallKit 和 Twilio-Video API 触发传入的 VoIP 调用
<p><p>通过使用 Twilio (<a href="https://github.com/twilio/video-quickstart-swift" rel="noreferrer noopener nofollow">VideoCallKitQuickStart</a>) 提供的示例视频通话应用程序之一,我试图通过向应用程序发送 VoIP 通知来触发来电。但该应用程序不会触发来电。我还尝试在发送 VoIP 通知时保持应用程序打开并且应用程序崩溃,方法是抛出以下异常</p>
<blockquote>
<p>NSInvalidArgumentException: Attempt to
insert non-property list object 'PKPushPayload: 0x16e44af0' for key
payload</p>
</blockquote>
<p>当收到 VoIP 通知时,有人可以帮助我或指出正确的方向,了解如何在应用中触发来电。</p>
<p>下面是我在 ViewController.swift 文件中的代码</p>
<pre><code> 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)
}
}
</code></pre></p>
<br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
<p><p>发布迟到的答案,但它可能对某人有帮助。</p>
<p>按照我处理语音来电的代码。</p>
<pre><code>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)
}
}
}
}
</code></pre>
<p>下面是我添加的call kit的委托(delegate)方法</p>
<pre><code>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
}
}
</code></pre>
<p>我已经按照 twilio 提供的这个教程 - <a href="https://github.com/twilio/voice-quickstart-swift" rel="noreferrer noopener nofollow">https://github.com/twilio/voice-quickstart-swift</a> </p>
<p>阅读本教程,它将起作用。</p></p>
<p style="font-size: 20px;">关于ios - 使用 CallKit 和 Twilio-Video API 触发传入的 VoIP 调用,我们在Stack Overflow上找到一个类似的问题:
<a href="https://stackoverflow.com/questions/41498841/" rel="noreferrer noopener nofollow" style="color: red;">
https://stackoverflow.com/questions/41498841/
</a>
</p>
页:
[1]