UI freezes when trying to drawlocation


When I’m trying to draw location in my app,
the location takes at least 10’’ to get drawn.

My problem is that during this time all elements in my UI are unresponsive.

Here is my code

- (void)viewDidAppear:(BOOL)animated {
    [super viewDidAppear:animated];
    EILRequestFetchLocation *fetchLocationRequest =
    [[EILRequestFetchLocation alloc] initWithLocationIdentifier:@"46"];
    [fetchLocationRequest sendRequestWithCompletion:^(EILLocation *location,
                                                      NSError *error) {
        if (location != nil) {
            self.location = location;
            self.locationView.showTrace = YES;
            self.locationView.rotateOnPositionUpdate = NO;
            self.locationView.locationBorderThickness = 2;
            self.locationView.locationBorderColor = [UIColor blackColor];
            [self.locationView drawLocation:self.location];
            [self.locationManager startPositionUpdatesForLocation:self.location];
        } else {
            NSLog(@"can't fetch location: %@", error);

Any ideas how to get around this?



Using GCD (Grand Central Dispatch) is the best solution. You can request all the data you need in a background thread, and perform UI changes or updates in your main thread to avoid freezing everything.

Here’s a simple example of GCD:

// Doing something on the main thread
dispatch_queue_t myQueue = dispatch_queue_create("My Queue",NULL);
dispatch_async(myQueue, ^{
    // Perform long running process
    dispatch_async(dispatch_get_main_queue(), ^{
        // Update the UI

// Continue doing other stuff on the 
// main thread while process is running.

Using GCD to fetch the location metadata off the main queue is definitely a good idea, but I think drawing the location needs to be performed on the main queue anyway. In any case, 10 seconds is definitely too long, so something’s wrong here.

I’ll try to reproduce on my side, and if I can, grab the output from the profiler. Or if you have a moment yourself, and could profile this and send us the output, that’d help a ton, thanks!

It looks like it’s not drawLocation that causes the freeze but [self.locationManager startPositionUpdatesForLocation:self.location];

The UI freezes for a significant amount of time before - (void)indoorLocationManager:(EILIndoorLocationManager *)manager didUpdatePosition:(EILOrientedPoint *)position withAccuracy:(EILPositionAccuracy)positionAccuracy inLocation:(EILLocation *)location starts getting called.

This happens also in a new app i made just to test this. In an other app with much more complicated view hierarchy the delegate method isn’t getting called at all.