简体   繁体   English

iOS:在CallKit中无法获取去电事件

[英]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. 我正在使用“ telprompt”通过我的应用进行呼叫,但是当呼叫结束时,我希望显示一个新的视图控制器并点击一个API来获取数据,所以我想接收一个事件来打开一个弹出窗口并点击API 。

I have tried using CallKit, but Delegate method is not getting called. 我尝试使用CallKit,但未调用Delegate方法。

here is my code. 这是我的代码。

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

I have conform to CXCallObserverDelegate 我符合CXCallObserverDelegate

In viewDidLoad: 在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. 上面的方法没有被调用,您可以看到我已经设置了委托,我不知道我在做什么错。

I was missing a strong reference to the callObserver object after creating a strong reference/property to my controller it works well. 在为控制器创建了很好的引用/属性后,我错过了对callObserver对象的强烈引用。

Add the property and put callObserver object in it. 添加属性并将callObserver对象放入其中。

@property (nonatomic, strong) CXCallObserver *callObserver;

viewDidLoad: viewDidLoad中:

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

Now Delegate method will be called. 现在将调用Delegate方法。

Cheers !!! 干杯!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM