Call status monitoring in iOS: CoreTelephony and ioscoretelephony
To listen to the phone status in the program, you can introduce the CoreTelephony framework, which includes telephone-related APIs to monitor incoming calls and view carrier information. The following is the specific code to monitor incoming calls. You must write the center as a separate attribute and use strong references. OtherwiseViewDidLoad
Create a center,ViewDidLoad
After the method is called, the center is destroyed and the incoming power cannot be detected.
The initial status of a call is CTCallStateIncoming and CTCallStateDialing. After the call is established, the call status changes to CTCallStateConnected, and when the call is terminated, the call status changes to CTCallStateDisconnected)
CTCallCenter * center = [[CTCallCenter alloc] init]; center _ = center; center. callEventHandler = ^ (CTCall * call) {NSLog (@ "call: % @", call. description); if ([call. callState isEqualToString: @ "CTCallStateDialing"]) {// call status} if ([call. callState isEqualToString: @ "CTCallStateDisconnected"]) {// disconnected }};