Intercepting calls from your app even from the background
From Apple documentation:
Use the CTCallCenter class to obtain a list of current cellular calls, and to respond to state changes for calls such as from a dialing state to a connected state. Such state changes are known as cellular call events.
The purpose of CTCallCenter is to give the developer the opportunity to pause his app state during a call in order to give the user the best experience.
First, we will define a new class member inside the class we want to handle the interceptions:
Inside our class init (constructor) we will allocate new memory for our class member:
Afterwards, we will invoke our new method that actually handles the interceptions:
That's it, if the user will use your app and will receive a phone call you could intercept this call and handle your app for a save state.
It is worth mentioning that there are 4 call states you can intercept:
Define your class member at the relevant class and define it:
What will happen if your app is in the background and you need to intercept calls while the app is in the background ?
For example, if you develop an enterprise app you can basically just add 2 capabilities (VOIP & Background fetch) in the Capabilities tab:
Your project target -> Capabilities -> Background Modes -> mark Voice over IP & Background fetch
This modified text is an extract of the original Stack Overflow Documentation created by following contributors and released under CC BY-SA 3.0