I am writing a Flutter application that uses VoIP notification. I have successfully integrated PushKit natively in iOS and it is invoking CallKit as well.
When the app is minimized and there is an incoming call, there is a call notification with a decline and answer button. It is a native VoIP CallKit Notification.
What I am trying to achieve is, when a user presses either the answer or decline button, I want to detect those button taps for performing some call declining functionality on the Flutter end.
Attaching some code here what I have done so far
func pushRegistry(_ registry: PKPushRegistry, didReceiveIncomingPushWith payload: PKPushPayload, for type: PKPushType, completion: @escaping () -> Void) {
let handle : String = payload.dictionaryPayload["handle"] as! String
// let uuidString : String = payload.dictionaryPayload["callUUID"] as! String
self.handleCallAndMethods(handle, completion: completion)
}
func callObserver(_ callObserver: CXCallObserver, callChanged call: CXCall) {
print(callObserver)
print("Call UUID = ")
print(call.uuid)
if call.isOutgoing == false && call.hasConnected == false && call.hasEnded == false {
print("Call has ended")
}
}
func handleCallAndMethods(_ handle : String, completion: @escaping () -> Void){
let config = CXProviderConfiguration(localizedName: "VoIP Service")
config.supportsVideo = true
config.supportedHandleTypes = [.phoneNumber]
config.maximumCallsPerCallGroup = 1
let callProvider : CXProvider = CXProvider(configuration: config)
// callProvider?.setDelegate(callManager, queue: nil)
let uuid : UUID = UUID()
print("Reaching inside call condition")
let callUpdate = CXCallUpdate()
let phoneNumber = CXHandle(type: .phoneNumber, value: handle)
print(phoneNumber)
callUpdate.remoteHandle = phoneNumber
print(callUpdate)
let bgTaskID = UIApplication.shared.beginBackgroundTask(expirationHandler: nil)
callProvider.reportNewIncomingCall(with: uuid,
update: callUpdate, completion: { (error) in
self.callObserver.setDelegate(self, queue: nil)
completion()
})
UIApplication.shared.endBackgroundTask(bgTaskID)
}
func provider(_ provider: CXProvider, perform action: CXAnswerCallAction) {
action.fulfill()
print("Answer button is pressed")
}
func provider(_ provider: CXProvider, perform action: CXEndCallAction) {
action.fulfill()
print("Calling is ended")
}