get a notification from notificationCenter after returning from a phone call

后端 未结 1 1380
故里飘歌
故里飘歌 2021-01-07 06:16

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 :



        
相关标签:
1条回答
  • 2021-01-07 06:51

    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")
            }
        }
    }
    
    0 讨论(0)
提交回复
热议问题