In the program if you need to monitor the status of the phone, you can introduce the Coretelephony framework, this framework contains the telephone-related APIs, can monitor incoming calls, look at operator information and other functions. The following is the specific implementation of the code to monitor incoming calls. Be sure to write Center as a separate attribute, and a strong reference (strong), otherwise if center is destroyed after the Center,viewdidload method is created in the Viewdidload method, then the call cannot be detected.
The initial state of a call is the incoming (ctcallstateincoming) and exhaled (ctcallstatedialing), when the state is switched on (ctcallstateconnected), And when the call is terminated, the state turns to hang up (ctcallstatedisconnected)
Ctcallcenter *center = [[Ctcallcenter alloc]init];
Center_ = center;
Center.calleventhandler = ^ (Ctcall *call) {
NSLog (@ "call:%@", call.description);
if ([Call.callstate isequaltostring:@ "ctcallstatedialing"]) {
//is calling status
}
if ([call.callstate isequaltostring:@ "ctcallstatedisconnected"]) {
//disconnect status
}
};
The above is a small set to introduce the iOS coretelephony to monitor the status of all the narration, hope to help everyone, if you want to know more content, please pay attention to cloud Habitat community website!