George Asda
George Asda

Reputation: 2129

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("http://itunes.apple.com/lookup?id=xxxxxxxxxxxxx") == true {

                  self.showAlertForUpdate()
                }
            })

Upvotes: 1

Views: 33

Answers (1)

Rich Tolley
Rich Tolley

Reputation: 3842

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.

Upvotes: 1

Related Questions