I am trying to add activity indicator while updating annotation on the map. But it seems not to work such a way. Application screen disables and becomes frozen once process of update is started, so that's why probably activity indicator is not visible.
My question is: Is it possible to update annotations on the map asynchronous with the app, so activity indicator would be visible.
I believe it is really annoying for the user not to see indicator if it takes more then 2 sec.
Solution:
self.activityIndicator.startAnimating()
dispatch_after(DISPATCH_TIME_NOW, dispatch_get_main_queue(), {
self.showPins(self.initialLat, locationLong: self.initialLong)
})
self.activityIndicator.stopAnimating()
You have to make sure you are doing these things:
1. Load all annotations at once
Apple recommends in the MKMapView Class Reference all annotations (pins) should be loaded at once:
2. Reuse your annotation views
You have to make sure you are correctly reusing existing annotation views by using dequeueReusableAnnotationViewWithIdentifier in the
viewForAnnotation
method.3. Do heavy loading on background threads
If you can't fetch / load the annotations at once you could use Grand Central Dispatch to let the 'heavy' method run on a background thread so the UI doesn't block. Note: any changes to the UI from within that method (on the bg thread) will need to explicitly happen on the main UI thread.
Regarding backgrounding, take a look at this Stackoverflow answer:
Or alternatively, use this 'Async' library for some syntactic sugar.