Coretelephony Framework, this framework contains telephone-related APIs that enable monitoring of incoming calls, and the ability to view operator information. Here is the specific code to implement monitoring calls
#import "ViewController.h"//Introducing Frames@import coretelephony;@interfaceViewcontroller () @property (nonatomic, strong) Ctcallcenter*Center;@end@implementationViewcontroller- (void) viewdidload {[Super viewdidload]; Self.center=[[Ctcallcenter alloc] init]; Self.center.callEventHandler= ^ (Ctcall *Call ) { //TODO: Processing After a call is detected };}@end
Note here that the center must be written as a separate attribute, and is a strong reference (strong), otherwise if the viewDidLoad
method to create a center, the viewDidLoad
method call after the center is destroyed, you can not detect the call, do not make such a low-level error.
How to monitor incoming calls in iOS