Search code examples
iosobjective-ciphoneios10callkit

iOS: Could not get outgoing call events in CallKit


I'm making a call through my app using 'telprompt', but when call ends I want a new view controller to be shown and hit an API to get data, So I want to receive an event to open a pop up and hit API.

I have tried using CallKit, but Delegate method is not getting called.

here is my code.

#import <CallKit/CXCallObserver.h>
#import <CallKit/CXCall.h>

I have conform to CXCallObserverDelegate

In viewDidLoad:

CXCallObserver *callObserver = [[CXCallObserver alloc] init];
[callObserver setDelegate:self queue:nil];

Delegate method:

- (void)callObserver:(CXCallObserver *)callObserver callChanged:(CXCall *)call {
    if (call.hasConnected) {
        NSLog(@"********** voice call connected **********/n");

    } else if(call.hasEnded) {

        NSLog(@"********** voice call disconnected **********/n");

    }
}

Above method is not getting called, As you can see I have already set delegate, I don't know what I am doing wrong.


Solution

  • I was missing a strong reference to the callObserver object after creating a strong reference/property to my controller it works well.

    Add the property and put callObserver object in it.

    @property (nonatomic, strong) CXCallObserver *callObserver;
    

    viewDidLoad:

    CXCallObserver *callObserver = [[CXCallObserver alloc] init];
    [callObserver setDelegate:self queue:nil];
    _callObserver = callObserver;
    

    Now Delegate method will be called.

    Cheers !!!