-->

how to integrate Callkit with Agora VOiP in swift

2019-08-25 06:14发布

问题:

I want to integrate apple Callkit with Agora VOiP in swift 4 iOS.

Please give any suggestions How can I do that.

回答1:

To integrate voip, you will have to use both, callKit and PushKit.

CallKit will be used to show native call screen and handlers during in call transition while Pushkit will be used to invoke app, when app is killed.

Its easy to integrate:-

Enable background modes in info.plist and check option "App provides Voice over IP services". Import Callkit in the viewcontroller viewdidload/ any init method of anyclass you would use to Implement CXProviderDelegate functions. Through this you will configure call objects, when to report in comming call, accept actions, reject action etc.

Implement the following functions:

func providerDidReset(_ provider: CXProvider) {
}

func provider(_ provider: CXProvider, perform action: CXAnswerCallAction) {
    action.fulfill()
}

func provider(_ provider: CXProvider, perform action: CXEndCallAction) {
    action.fulfill()
}

Now import Pushkit and implement PKPushRegistryDelegate functions.

a.)Configure pushkit like this

let registry = PKPushRegistry(queue: nil)
        registry.delegate = self
        registry.desiredPushTypes = [PKPushType.voIP]

b.) implement pushkit token function. You may have to update to server for delivering voip push notifications

 func pushRegistry(_ registry: PKPushRegistry, didUpdate pushCredentials: PKPushCredentials, for type: PKPushType) {
        print(pushCredentials.token.map { String(format: "%02.2hhx", $0) }.joined())
    }

c. Now when you receive incomming notification, implement this fuction

func pushRegistry(_ registry: PKPushRegistry, didReceiveIncomingPushWith payload: PKPushPayload, for type: PKPushType, completion: @escaping () -> Void) {
        let config = CXProviderConfiguration(localizedName: "App name")
        config.iconTemplateImageData = UIImagePNGRepresentation(UIImage(named: "any image name")!)

        config.supportsVideo = true;
        let provider = CXProvider(configuration: config)
        provider.setDelegate(self, queue: nil)
        let update = CXCallUpdate()
        update.remoteHandle = CXHandle(type: .generic, value: "Caller name")
        update.hasVideo = true
        provider.reportNewIncomingCall(with: UUID(), update: update, completion: { error in })
    }
  1. Go to developer portal and generate VoIP Services certificate and install it.
  2. Enable push notifications under Capabilities.

This was a basic code over view. You will have to add cases to simulating incomming call and other customizations. I hope this will help you to move further.