iOS How to determine what is blocking the UI

user379468 picture user379468 · Apr 10, 2013 · Viewed 22.4k times · Source

I'm fairly new to iOS development but I'm starting to grasp some of the more complicated concepts. I currently have an application that implements an AVCam to capture video. The AVCam is created on a separate thread, but uses a view that is in my main xib file. When the camera is done capturing, it calls a complete function in my ViewController class. Within the complete function I call a number of other functions that update the UI as well as a few NSLogs. Everything seems to work fine, I see the logs in the console immediately, but the UI takes another 3 seconds to update. I've tried using instruments to find the offending code, but I can't seem to find it. Is there another way to determine what is blocking by UI?

Here is the code called when the recording is complete;

-(void)movieRecordingCompleted{
       [HUD hide:YES];
        NSLog(@"movieRecordingCompleted");
        [self showModalViewController];
        NSString *pathToMovie = [NSHomeDirectory() stringByAppendingPathComponent:@"Documents/Movie.mov"];
        NSLog(@"pathToMovie: %@", pathToMovie);
        pathToTreatedVid = pathToMovie;
        NSLog(@"File Save Called");
        UISaveVideoAtPathToSavedPhotosAlbum(pathToMovie, nil, NULL, NULL);
}

Everything is logged immediately, but the progress HUD and the modal view controller don't trigger for about 2 - 5 seconds, it's very strange.

Here is the before and after state of the threads (when it is frozen vs when it becomes unfrozen). enter image description here enter image description here

Answer

Ossir picture Ossir · Apr 10, 2013

Try to Pause program execution (there is a button for that in bottom panel of Xcode, the third one)

Pause

  • Then look at left panel (Navigator panel),
  • Find Debug Navigator

Debug Navigator

  • Find thread with main function, and mb you can figure out by methods in this thread, what takes so long to update your UI. The method that are working right now is the top black one usually(with grey colour listed obj-c internal methods).

main