菜鸟教程小白 发表于 2022-12-11 18:30:17

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 &#39;PKPushPayload: 0x16e44af0&#39; 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: &#34;testRoom&#34;, completion: nil)
    }

func reportIncomingCall(uuid: UUID, roomName: String?, completion: ((NSError?) -&gt; Void)? = nil) {

    let callHandle = CXHandle(type: .generic, value: roomName ?? &#34;&#34;)
    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(&#34;Incoming call successfully reported.&#34;)
      } else {
            NSLog(&#34;Failed to report incoming call successfully: \(error?.localizedDescription).&#34;)
      }
      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(&#34;pushRegistry:didReceiveIncomingPushWithPayload:forType:&#34;)
    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 () -&gt; Void) {
    NSLog(&#34;pushRegistry:didReceiveIncomingPushWithPayload:forType:completion:&#34;)

    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[&#34;twi_message_type&#34;] as? String
      if let messageType = msgType{
            if messageType == &#34;twilio.voice.call&#34;{
                fireLocalNotificationForVoiceCall(didStart: true)
            }else if messageType == &#34;twilio.voice.cancel&#34;{
                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]
查看完整版本: ios - 使用 CallKit 和 Twilio-Video API 触发传入的 VoIP 调用