iosiphonecallkit

How to end a phone call on iOS by callkit?


I want to end a phone call by callkit api. But I get this information "com.apple.CallKit.error.requesttransaction error 4". I don't know why and what happen. By the way, the phone call is real call, not a VOIP call.

CallKit CXError.h CXErrorCodeRequestTransactionErrorUnknownCallUUID 4

Prepare, enable voip for com.apple.CallKit.error.requesttransaction error 1 & create global variable CXCallController *callController enter image description here

First, I use CXCallObserver get call UUID

- (void)callObserver:(CXCallObserver *)callObserver callChanged: (CXCall *)call {
}

Followed, I use some api to end the phone and I put it in callObserver

    NSUUID *callUUID = call.UUID;
    CXEndCallAction *endaction = [[CXEndCallAction alloc] initWithCallUUID:callUUID];
    CXTransaction *transaction = [[CXTransaction alloc] initWithAction:endaction];

    [self.callController requestTransaction:transaction completion:^(NSError * _Nullable error) {
        if (error) {
            NSLog(@"EndCallAction transaction request failed: %@", [error localizedDescription]);
        } else {
            NSLog(@"EndCallAction transaction request successful");
        }
    }];

Finally, I get this. PS: The UUID is not empty. enter image description here

I have referenced How to end a call in CallKit. But no use. I have no idea. Please help or try to give some ideas how to achieve this. Thanks!


Solution

  • You can only use CallKit to manage VoIP calls that were established by your app. You cannot manage cellular calls or VoIP calls from other apps.