iOS CoreTelephony realizes monitoring call status

  • 2020-06-19 11:46:15
  • OfStack

In the program, if you need to monitor the status of the phone, you can introduce CoreTelephony framework. This framework contains the telephone-related API, which can realize the functions such as monitoring calls and viewing operator information. The following is the specific implementation of the call monitoring code. 1 Make sure center is a separate property and is a strong reference (strong), otherwise if center is created in viewDidLoad method, center will be destroyed after the viewDidLoad method is called, and incoming power cannot be detected.

The initial state of 1 call is incoming (CTCallStateIncoming) and outgoing (CTCallStateDialing). The state changes to on (CTCallStateConnected) when connected and to hang up (CTCallStateDisconnected) when the call terminates.


CTCallCenter *center = [[CTCallCenter alloc]init];
center_ = center;
center.callEventHandler = ^(CTCall *call){
NSLog(@"call:%@",call.description);
if ([call.callState isEqualToString:@"CTCallStateDialing"]) {
// Calling status 
}
if ([call.callState isEqualToString:@"CTCallStateDisconnected"]) {
// Disconnected state 
}
};

Above is the site to you iOS coretelephony implementation of monitoring the status of all the description, I hope to help you, if you want to learn more content, please pay attention to this site!


Related articles: