George Asda George Asda - 10 months ago 52
iOS Question

Getting the following error: This application is modifying the autolayout engine from a background thread

I get this warning with this code.
I am checking in the background if an update is available. And then present an alert.
Obviously Xcode and iOS don't like my thinking... any ideas?

dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), {

if CheckAppUpdate().appUpdateAvailable("") == true {



In iOS all UI code must run on the main thread. You are dispatching to a background thread in order to perform your update check, which is fine, but then trying to update the UI from that same background thread, which is causing the error you are seeing. The solution is to add another dispatch_async inside the first one, wrapping the call to self.showAlertForUpdate(), but dispatching to the main queue (dispatch_get_main_queue(...) instead.