I’m making server requests to a server on different threads. When they are done loading, I get a delegate callback which updates a tableView. At first, I noticed some strange behavior, and figured it might be because some UI elements weren’t performed on the main thread.
I added the code below, which solved the problem, but the code crashed on iOS 4 devices (Turns out DISPATCH_QUEUE_PRIORITY_BACKGROUND isn’t compatible with iOS 4)
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_BACKGROUND,0), ^(void) {
dispatch_async(dispatch_get_main_queue(), ^(void) {
//Update view code etc...
});
});
If I remove the first dispatch_async, and only call dispatch_get_main_queue, the code runs fine:
dispatch_async(dispatch_get_main_queue(), ^(void) {
//Update view code etc...
});
Before sending in my update to Apple, I wanted to ask if this is okay to do? Will the code run correctly on iOS 4 devices?
Thanks in advance.
DISPATCH_QUEUE_PRIORITY_BACKGROUNDis only available in iOS 5 and upperFrom apple docs
So if you are thinking of distributing your app for iOS 4 too, then you cant use it
Source apple docs
However if you remove the
DISPATCH_QUEUE_PRIORITY_BACKGROUND, your current code will only run in the main ui thread, wich may lead to slow downs when you are doing your remote requests