Stalling when panning/zooming map

I have an app that shows where busses are on their routes. Many times when panning around or trying to zoom in or out the app stalls. When location manager makes a call to didUpdateLocations, I reload the map with the possible change in the bus location. To get the change information I have to use NSURL to grab an xml file and parse it for bus route name, gps data, etc. Is this nsurl call blocking the app? Is there a way to put this call on a different thread so it is not blocking the pan/zoom actions on the map?


Is there a better forum to ask this question?


Thanks

If you hit "pause" in the debugger while the app is "stalled" then you can see what the main thread is doing. Yes if you are making a synchronous network call from the main thread then it can block it and cause the app to become unresponsive. Whether that's actually what's happening in your case is impossible to tell without knowing any details about your app.


The solution, if you are doing networking on the main thread, is to use an asynchronous API such as NSURLSession. You do have to ensure that any UI updates (e.g. adding map overlays or annotations) are done on the main thread after you're done receiving the data from the network. Consult the NSURLSession class reference and pay special attention to the method parameters that specify the queue to which callbacks should be delivered.


Alternatively you can use GCD (dispatch_async to a background queue) and synchronous calls but NSURLSession is probably a better approach.

I used this article and it helped. I put the the loadmaps in some code like this:


dispatch_async(GlobalUserInitiatedQueue) {

dispatch_async(self.GlobalMainQueue) {

self.loadMaps()

}

}


It seems to be way better.

I did use dispatch_async. See my other note.


thanks

Stalling when panning/zooming map
 
 
Q