在CTCallCenter callEventHandler中取消隐藏视图非常慢 [英] Unhiding a view is very slow in CTCallCenter callEventHandler

查看:105
本文介绍了在CTCallCenter callEventHandler中取消隐藏视图非常慢的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在原始问题未得到答复后,重新提交更简洁,更有针对性的问题。在另一天的研究之后还要更深入地了解问题:

Reposting with more concise and focused question after original question went unanswered. Also adding more insight into the problem after another day of research:

在我的app delegate( didFinishLaunching )中,我在 CTCallCenter 上设置 callEventHandler
我的想法是当callState发生变化时,我发布了一个包含 call.callState 的userInfo dict
的通知。在我看来,我观察到这个通知,当
userInfo dict包含值 CTCallDisconnected 时,我想取消隐藏一个观点。

In my app delegate (didFinishLaunching), I set up a callEventHandler on CTCallCenter. The idea is that when a callState changes, I post a notification with a userInfo dict containing the call.callState. In my view, I observe this notification, and when the userInfo dict contains a value of CTCallDisconnected, I want to unhide a view.

我遇到的问题是,取消隐藏的方面几乎是一致的,约7秒。
其他一切都运行正常,我知道这是因为我在取消隐藏之前和之后 NSLog
和那些日志会立即出现,但是看得见的远景仍然滞后7秒。

The problem I'm having is that the unhiding aspect is taking, almost consistenly, ~ 7 seconds. Everything else is working fine, and I know this because I NSLog before and after the unhiding, and those logs appear immediately, but the darned view still lags for 7 seconds.

这是我的代码:

appDidFinishLaunching:

appDidFinishLaunching:

self.callCenter = [[CTCallCenter alloc] init];
    self.callCenter.callEventHandler = ^(CTCall* call) {
        // anounce that we've had a state change in our call center
        NSDictionary *dict = [NSDictionary dictionaryWithObject:call.callState forKey:@"callState"];
        [[NSNotificationCenter defaultCenter] postNotificationName:@"CTCallStateDidChange" object:self userInfo:dict];
    };

当用户点击拨打电话号码的按钮时,我会收听此通知:

I then listen for this notification when a user taps a button that dials a phone number:

[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(ctCallStateDidChange:) name:@"CTCallStateDidChange" object:nil];

然后,在ctCallStateDidChange中:

Then, in ctCallStateDidChange:

- (void)ctCallStateDidChange:(NSNotification *)notification
{
   NSLog(@"121");
   NSString *callInfo = [[notification userInfo] objectForKey:@"callState"];
   if ([callInfo isEqualToString:CTCallStateDisconnected]) {
      NSLog(@"before show");
      [self.view viewWithTag:kNONEMERGENCYCALLSAVEDTOLOG_TAG].hidden = NO;
      NSLog(@"after show");
   }
}

我已将问题追踪到if条件在上面的代码示例中:

I've tracked the problem down to the if condition in the above code sample:

 if ([[userInfo valueForKey:@"userInfo"] valueForKey:@"callState"] == CTCallStateDisconnected) {

如果我只是将其替换为:

If I simply replace that with:

if (1 == 1) {

然后立即显示视图!

问题是,那些 NSLog 语句是立即记录的,但视图是
落后于它的隐藏。那个条件怎么可能只导致它的一部分块
立即执行,其余的等待~7秒?

The thing is, those NSLog statements are logging immediately, but the view is lagging in it's unhiding. How could that condition cause only part of it's block to execute immediately, and the rest to wait ~ 7 seconds?

谢谢!

推荐答案

尝试将您的代码更改为:

Try changing your code to this:

- (void)ctCallStateDidChange:(NSNotification *)notification
{
   NSLog(@"121");
   NSString *callInfo = [[notification userInfo] objectForKey:@"callState"];
   if ([callInfo isEqualToString:CTCallStateDisconnected]) {
      NSLog(@"before show");
      [self.view viewWithTag:kNONEMERGENCYCALLSAVEDTOLOG_TAG].hidden = NO;
      NSLog(@"after show");
   }
}

注意:


  • 参数是 NSNotification ,而不是 NSDictionary

  • 我不会比较字符串与 ==

  • 无需转换视图来更改隐藏属性

  • 使用而不是 false

  • The parameter is an NSNotification, not an NSDictionary
  • I would not compare strings with ==
  • No need to cast the view to change the hidden property
  • Use NO instead of false

更新:明白了:您可以尝试以下方法吗? ,在 NSLog 之间?

Update: Got an idea: Could you try the following, please, in between the NSLogs?

dispatch_async(dispatch_get_main_queue(), ^{
   [self.view viewWithTag:kNONEMERGENCYCALLSAVEDTOLOG_TAG].hidden = NO;
});

阅读 CTCallCenter doc,似乎是 callEventHandler 在默认优先级全局调度队列上调度,该队列不是发生所有UI内容的主队列。

Reading the CTCallCenter doc, it seems the callEventHandler is dispatched on "the default priority global dispatch queue", which is not the main queue where all the UI stuff happens.

这篇关于在CTCallCenter callEventHandler中取消隐藏视图非常慢的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆