i have this code:
https://stackoverflow.com/a/50999497/19364094
and when i try to call func showCallAlert() from another ViewController it it not working for me and it not detect if user click call or cancel
what it can do?
i have this code:
https://stackoverflow.com/a/50999497/19364094
and when i try to call func showCallAlert() from another ViewController it it not working for me and it not detect if user click call or cancel
what it can do?
The code in that link is from 2012, with updates in 2018 etc. Can you post your actual code, and let us know which version of iOS you're targeting, etc.?
This Code: I mean version ios 14 and up
var didDetectOutgoingCall = false
func showCallAlert() {
guard let url = URL(string: "tel:+36201234567"),
UIApplication.shared.canOpenURL(url) else {
return
}
callObserver.setDelegate(self, queue: nil)
didDetectOutgoingCall = false
UIApplication.shared.open(url, options: [:]) { [weak self] success in
if success {
DispatchQueue.main.asyncAfter(deadline: .now() + 0.3) {
self?.addNotifObserver()
}
}
}
}
func addNotifObserver() {
let selector = #selector(appDidBecomeActive)
let notifName = UIApplication.didBecomeActiveNotification
NotificationCenter.default.addObserver(self, selector: selector, name: notifName, object: nil)
}
@objc func appDidBecomeActive() {
//if callObserver(_:callChanged:) doesn't get called after a certain time,
//the call dialog was not shown - so the Cancel button was pressed
DispatchQueue.main.asyncAfter(deadline: .now() + 0.3) { [weak self] in
if !(self?.didDetectOutgoingCall ?? true) {
print("Cancel button pressed")
}
}
}
func callObserver(_ callObserver: CXCallObserver, callChanged call: CXCall) {
if call.isOutgoing && !didDetectOutgoingCall {
didDetectOutgoingCall = true
print("Call button pressed")
}
}
if i can the func showCallAlert() from anther viewcontroller it not detected if print("Cancel button pressed") or print("Call button pressed"), why?