[ad_1]
I’m making an attempt to detect when the person will get a telephone name. I’ve tried the next:
import CallKit
class ViewController: UIViewController, UIApplicationDelegate {
var callObserver: CXCallObserver!
var participant: AVAudioPlayer?
override func viewDidLoad() {
tremendous.viewDidLoad()
callObserver = CXCallObserver()
callObserver.setDelegate(self, queue: nil)
}
}
extension ViewController: CXCallObserverDelegate {
func callObserver(_ callObserver: CXCallObserver, callChanged name: CXCall) {
if name.hasEnded == true {
print("Disconnected")
}
if name.isOutgoing == true && name.hasConnected == false {
print("Dialing")
}
if name.isOutgoing == false && name.hasConnected == false && name.hasEnded == false {
print("Incoming")
}
if name.hasConnected == true && name.hasEnded == false {
print("Related")
}
}
This appears to work nice whereas the app is within the foreground. Nevertheless it’s not fairly working whereas the app is within the background.
That is the primary time I’m making an attempt to execute codes from the background. That is the strategy I took proper now. Am I doing it proper?
[ad_2]


