I have implemented pull to refresh within my app which when pulled starts the location manager to get a fix on the users location then presents a modal view controller showing that location.
The problem I'm having is that the modal view controller is being presented before the users location has been obtained resulting a blank map for a few more seconds until it's obtained and updated.
I have a property that holds the users current location. Is it possible to 'hold' until that property is not nil (ie. a location has been established) before the pull to refresh calls 'showMap', perhaps if it can't locate the user after a set time it just presents an error? I tried using a 'while' loop to constantly check the currentLocation property but it didn't seem like the right thing to do and didn't work anyway.
This is my pull to refresh code which is set-up in viewDidLoad:
__typeof (&*self) __weak weakSelf = self;
[self.scrollView addPullToRefreshWithActionHandler:^ {
int64_t delayInSeconds = 1.0;
dispatch_time_t popTime = dispatch_time(DISPATCH_TIME_NOW, delayInSeconds * NSEC_PER_SEC);
dispatch_after(popTime, dispatch_get_main_queue(), ^(void){
[weakSelf showMap];
});
}];
When the pull to refresh is used it calls these methods:
- (void)showMap
{
[self.locationManager updateCurrentLocation];
[NSTimer scheduledTimerWithTimeInterval:2.0 target:self selector:@selector(finishRefresh) userInfo:nil repeats:NO];
}
- (void)finishRefresh
{
[self.scrollView.pullToRefreshController didFinishRefresh];
[self performSegueWithIdentifier:@"showMap" sender:self];
}