本文介绍了设置callEventHandler后,CTCallCenter不会更新currentCalls属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试查看是否有任何正在进行的呼叫,但是在将CTCallCenter实例保留为属性时遇到了麻烦.基本上,这就是我正在调试的内容(所有内容都在MyClass中):

I'm trying to see if there are any ongoing calls, but I'm having trouble with keeping an instance of CTCallCenter as a property. Here's basically what I'm doing now that I'm debugging (everything is in MyClass):

-(void)checkForCurrentCalls
{
    CTCallCenter *newCenter = [[CTCallCenter alloc] init];
    if (newCenter.currentCalls != nil)
    {
        NSLog(@"completely new call center says calls in progress:");
        for (CTCall* call in newCenter.currentCalls) {
            NSLog(call.callState);
        }
    }
    if (self.callCenter.currentCalls != nil) {
        NSLog(@"property-call center says calls in progress:");

        for (CTCall* call in self.callCenter.currentCalls) {
            NSLog(call.callState);
        }
    }
}

我的self.callCenter是一个 @属性(非原子性强)CTCallCenter * callCenter; .它已经合成了setter和getter.它是在MyClass的init方法中初始化的:

My self.callCenter is a @property (nonatomic, strong) CTCallCenter *callCenter;. It has synthesized setter and getter. It's initialized in MyClass' init method:

- (id)init
{
    self = [super init];
    if (self) {
        self.callCenter = [[CTCallCenter alloc] init];
    }
    return self;
}

如果我在 checkForCurrentCalls 之前调用另一个方法,则我的 self.callCenter.currentCalls 会停止更新其应有的方式.更准确地说,我(对我自己)打的电话一直在堆积,因此,如果我拨打并挂断了三个电话,我会得到三个处于拨号"状态的CTCall的打印输出.newCenter可以正常工作.

If I call another of my methods before checkForCurrentCalls, then my self.callCenter.currentCalls stops updating the way it should. More precisely, the phonecalls I make (to myself) just keep piling on, so that if I've dialed and hung up three phonecalls I get printouts of three CTCalls being in the "dialing" state. The newCenter works as expected.

我要做的就是打破它:

- (void)trackCallStateChanges
{
    self.callCenter.callEventHandler = ^(CTCall *call)
    {

    };
}

我碰到的答案是CTCallCenter必须在主队列上进行分配初始化.从那以后,我一直在使用我的应用程序委托中的dispatch_async,只在主队列上调用自己的 init :

I have come across answers that say that CTCallCenter has to be alloc-init'd on the main queue. I have since then taken care to only call my own init on the main queue, using dispatch_async from my app delegate:

        dispatch_async(dispatch_get_main_queue(), ^{
            self.myClass = [[MyClass alloc] init];
            [self.myClass trackCallStateChanges];
        }

稍后在 applicationWillEnterForeground 中调用我的 checkForCurrentCalls .

我不明白为什么只设置 callEventHandler -块会破坏它.一切都在iPhone 5 iOS 7.1.2上进行了测试.

I don't understand why just setting the callEventHandler-block breaks it.Everything is tested on iphone 5 ios 7.1.2.

推荐答案

这已在新项目中复制.提交了一个错误报告.

This has been reproduced in a new project. Filed a bug report on it.

这篇关于设置callEventHandler后,CTCallCenter不会更新currentCalls属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-27 19:54