I wanted to try to detect incoming phone calls in my app. I created a new Swift project from scratch just to try some code. The only thing I did was importing CoreTelephony in the ViewController that is created with every new project and I also changed the viewDidLoad() to:
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
let callCenter = CTCallCenter()
NSLog("start")
callCenter.callEventHandler = {[weak self] (call: CTCall) -> () in
self?.label.text = call.callState
NSLog("Call state")
NSLog(call.callState)
}
I also tried without the [weak self] since I am new to swift and not sure of what it entails.
When I run my new little app via XCode on my phone nothing happens when a call is received, disconnected or anything else. No error what so ever. Do I have to do something more in order to use the CoreTelephony framework and the CTCallCenter?
Regards Johan