George Asda George Asda - 1 year ago 103
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 {


Answer Source

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.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download