preface

I wrote an article about the replacement of THE SDK of CallKit before. At that time, due to careless consideration, I found that the SDK was prohibited to be used in China after the replacement and could not be put on the shelves. Therefore, I replaced the original SDK, which is now on the shelves, and you can rest assured to use it.

The body of the

Import libraries

#import <CoreTelephony/CTCall.h>
#import <CoreTelephony/CTCallCenter.h>
Copy the code

application

To facilitate use in different places, it is recommended to use global variables as initializers, and then use the following core code for logical processing

// initialize @property (strong, nonatomic) CTCallCenter * callCenter; self.callCenter = [[CTCallCenter alloc] init]; self.callCenter.callEventHandler = ^(CTCall *call) { @strongify(self); if ([call.callState isEqualToString:CTCallStateDisconnected]) { dispatch_async(dispatch_get_main_queue(), ^{ @strongify(self); // The operation needed to disconnect the phone}; } else if([call.callState isEqualToString:CTCallStateIncoming]) { dispatch_async(dispatch_get_main_queue(), ^{ @strongify(self); // What to do when calling}; } else {DLog(@" unknown "); }};Copy the code

extension

For the current project, only two cases are used, and the system provides four cases to identify, and you can try in the required scene

CTCallStateDialing
CTCallStateIncoming
CTCallStateConnected
CTCallStateDisconnected
Copy the code

The end of the

Above is for telephone and hang up to monitor method in iOS, actually not difficult to content, the learned a very serious problem, is anything before actual application must be fully research before making decisions, or it will appear foreseen problem, lead to a waste of time, and made relatively useless work.