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

后端 未结 3 740
旧时难觅i
旧时难觅i 2021-01-21 11:38

By using one of the sample video calling app provided by Twilio (VideoCallKitQuickStart), I am trying to trigger an incoming call by sending a VoIP notification to the App. But

3条回答
  •  夕颜
    夕颜 (楼主)
    2021-01-21 12:05

    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.

提交回复
热议问题