I want to do an action after the user tapped on the call button and made a call then returned to the app.
This is my function for making a phone call :
You can use CXCallObserver
to listen the call events as below,
import CallKit
class ViewController: UIViewController, CXCallObserverDelegate {
let co = CXCallObserver()
override func viewDidLoad() {
super.viewDidLoad()
co.setDelegate(self, queue: DispatchQueue.main)
}
func callObserver(_ callObserver: CXCallObserver, callChanged call: CXCall) {
if call.hasEnded {
print("Call is ended")
}
if call.hasEnded == false && call.hasConnected {
print("Call is connected")
}
if call.isOutgoing {
print("This is an outgoing call")
} else if call.hasEnded == false && call.hasConnected == false {
print("This is an incoming call")
}
}
}