簡體   English   中英

設置callEventHandler后,CTCallCenter不會更新currentCalls屬性

[英]CTCallCenter doesn't update the currentCalls property after I set callEventHandler

我正在嘗試查看是否有任何正在進行的呼叫,但是在將CTCallCenter實例保留為屬性時遇到了麻煩。 基本上,這就是我正在調試的內容(所有內容都在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是@property @property (nonatomic, strong) CTCallCenter *callCenter; 它已經合成了setter和getter。 它是在MyClass的init方法中初始化的:

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

如果在checkForCurrentCalls之前調用另一個方法,則self.callCenter.currentCalls停止更新其應有的方式。 更准確地說,我(對我自己)打的電話一直在堆積,因此,如果我撥打並掛斷了三個電話,我會得到三個處於“撥號”狀態的CTCall的打印輸出。 newCenter可以正常工作。

我要做的就是打破這個困境:

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

    };
}

我遇到的回答是CTCallCenter必須在主隊列上進行alloc-initd初始化。 從那以后,我一直在使用從我的應用程序委托中使用dispatch_async僅在主隊列上調用自己的init的方法:

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

我的checkForCurrentCalls稍后在applicationWillEnterForeground調用。

我不明白為什么只設置callEventHandler會破壞它。 一切都在iPhone 5 iOS 7.1.2上進行了測試。

這已在一個新項目中復制。 提交了錯誤報告。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM