最近在調OC和UIWebview JS進行交互,打開含有Web的頁面時就會報下面的錯誤,后來發現是因為在JS調用OC是在子線程中,如果JS調OC 要更新當前UI的話就要放在主線程里。
This application is modifying the autolayout engine from a background thread after the engine was accessed from the main thread. This can lead to engine corruption and weird crashes.
沒加在主線程之前的代碼
weakself.context[@"jsViewFinish"] = ^() {
//結束加載動畫
[weakself stopLoadingDataAnimation];
};
加入主線程后的代碼
weakself.context[@"jsViewFinish"] = ^() {
dispatch_async(dispatch_get_main_queue(), ^{
[weakself stopLoadingDataAnimation];
});
};