Direct viewing in CTCallCenter is very slow. CallEventHandler

The permutation with a more concise and focused question after the initial question remained unanswered. Also adding a more detailed description of the problem after the next day of the study:

In my application delet ( didFinishLaunching ) I configured a callEventHandler to CTCallCenter . The idea is that when the callState state changes, I send a notification using the userInfo dict containing call.callState . In my opinion, I am watching this notification, and the userInfo dict contains the value CTCallDisconnected , I want to display the view.

The problem I am facing is that the invisible aspect takes, almost sequentially, ~ 7 seconds. Everything else works fine, and I know this because I have NSLog before and after opening, and these logs appear immediately, but the damned look is still 7 seconds behind.

Here is my code:

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]; }; 

Then I listen to this notification when the user presses a button dialing a phone number:

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

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"); } } 

I traced the problem to the if condition in the above code example:

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

If I just replace this:

 if (1 == 1) { 

Then the show will appear immediately!

The fact is that those NSLog statements are registered immediately, but the view is lagging behind it. How can this condition cause only part of its block to be executed immediately, and the rest wait ~ 7 seconds?

Thanks!

+7
source share
4 answers

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"); } } 

Note:

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

Update . An idea came up. Could you try the following, please, between NSLog s?

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

Considering the CTCallCenter doc, it seems that the callEventHandler sent to the "global default priority dispatch queue", which is not the main queue where all user interface content occurs.

+10
source

There seems to be no problem with your hidden code. If I were you, I would comment out all the code after the call was completed and uncomment it one by one to find out what the problem was.

0
source

Hm ... try calling [yourViewController.view setNeedsDisplay] after changing the hidden property. Or avoid hidden ones, use the alpha or addSubview: and removeFromSuperview methods instead.

0
source

djibouti33,

Where do you put this sentence to listen when the user clicks the button that dials the phone number? on the WillResignActive function?

this sentence β†’ [[NSNotificationCenter defaultCenter] addObserver: self selector: @selector (ctCallStateDidChange :) name: @ "CTCallStidDidChange" object: nil];

Thank you for your time,

Willie.

0
source

All Articles