-->

Can Callkit be used with non-voip call to get the

2020-07-09 09:10发布

问题:

I have read the question about making a-non-voip-call and it seems, that the open url is the only way to do it. Since CoreTelephony is deprecated, is it possible to use Callkit to get the call states when making a call with open url? If not is there any way to get the call states programmatically? I am developing an in-house-app.

How can CallKit be used to make a non-voip call?

Thanks in advance!!

回答1:

To get call states in CallKit, you can use CXCallObserver in your app.

import CallKit

final class ProviderDelegate: NSObject, CXCallObserverDelegate { 
var callObserver: CXCallObserver!

func setupCallObserver(){
callObserver = CXCallObserver()
callObserver.setDelegate(self, queue: nil)
}

func callObserver(_ callObserver: CXCallObserver, callChanged call: CXCall) {
        if call.hasEnded == true {
            print("CXCallState :Disconnected")
        }
        if call.isOutgoing == true && call.hasConnected == false {
            print("CXCallState :Dialing")
        }
        if call.isOutgoing == false && call.hasConnected == false && call.hasEnded == false {
            print("CXCallState :Incoming")
        }

        if call.hasConnected == true && call.hasEnded == false {
            print("CXCallState : Connected")
        }
    }
}