Trigger an incoming VoIP call using CallKit and Twilio-Video API

强颜欢笑 提交于 2019-12-02 02:02:41

Twilio developer evangelist here.

I'm not particularly good with iOS, but taking a quick look at the documentation for the PKPushRegistryDelegate it looks like your pushRegistry function definition isn't right.

It should be

func pushRegistry(_ registry: PKPushRegistry, 
    didReceiveIncomingPushWith payload: PKPushPayload, 
    forType type: PKPushType)

That is, didReceiveIncomingPushWith rather than didReceiveIncomingPushWithPayload.

Alternatively, does it have anything to do with the fact that you're casting forType to 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)
    }
}

And please don't make any changes in payload without modifying it in order for the SDK to extract the incoming call info out of the payload so that the SDK can notify the application with incoming calls

Posting late answer but it may helpful for someone.

Following code I did to handle voice incoming call.

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)
            }
        }
    }
}

Below are the delegate methods of call kit I have added

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
  }
}

I have followed this tutorial provided by twilio - https://github.com/twilio/voice-quickstart-swift

Go through this tutorial and it will work.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!