Getting the following error: This application is modifying the autolayout engine from a background thread
Getting the following error: This application is modifying the autolayout engine from a background thread
我收到此代码的警告。
如果有可用更新,我正在后台检查。然后发出警报。
显然 Xcode 和 iOS 不喜欢我的想法...有什么想法吗?
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), {
if CheckAppUpdate().appUpdateAvailable("http://itunes.apple.com/lookup?id=xxxxxxxxxxxxx") == true {
self.showAlertForUpdate()
}
})
在iOS中所有UI代码必须运行在主线程上。您正在分派到后台线程以执行更新检查,这很好,但随后尝试从同一后台线程更新 UI,这会导致您看到的错误。解决方案是在第一个队列中添加另一个 dispatch_async
,将调用包装到 self.showAlertForUpdate()
,而是分派到主队列 (dispatch_get_main_queue(...
)。
我收到此代码的警告。 如果有可用更新,我正在后台检查。然后发出警报。 显然 Xcode 和 iOS 不喜欢我的想法...有什么想法吗?
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), {
if CheckAppUpdate().appUpdateAvailable("http://itunes.apple.com/lookup?id=xxxxxxxxxxxxx") == true {
self.showAlertForUpdate()
}
})
在iOS中所有UI代码必须运行在主线程上。您正在分派到后台线程以执行更新检查,这很好,但随后尝试从同一后台线程更新 UI,这会导致您看到的错误。解决方案是在第一个队列中添加另一个 dispatch_async
,将调用包装到 self.showAlertForUpdate()
,而是分派到主队列 (dispatch_get_main_queue(...
)。