我是靠谱客的博主 鲤鱼狗,最近开发中收集的这篇文章主要介绍iOS 13 报错:[Assert] Unsupported use of UIKit view-customization API off the main thread,觉得挺不错的,现在分享给大家,希望可以做个参考。
概述
萤石摄像头回看,在iOS 11上运行好好,在iOS 13上却报错了,报错如下:
2021-05-11 15:36:38.174462+0800 App-Beta[1141:430280] [Assert] Unsupported use of UIKit view-customization API off the main thread. -setBackgroundColor: sent to <UIPickerTableView: 0x105ab2800; frame = (31 -37.6667; 103 291); clipsToBounds = YES; gestureRecognizers = <NSArray: 0x2811fc4b0>; layer = <CALayer: 0x281e0ed60>; contentOffset: {0, 0}; contentSize: {0, 0}; adjustedContentInset: {0, 0, 291, 0}; dataSource: (null)>
2021-05-11 15:36:38.175889+0800 App-Beta[1141:430280] [Assert] Unsupported use of UIKit view-customization API off the main thread. -_setBackgroundEffects: sent to <UIPickerTableView: 0x105ab2800; frame = (31 -37.6667; 103 291); clipsToBounds = YES; gestureRecognizers = <NSArray: 0x2811fc4b0>; layer = <CALayer: 0x281e0ed60>; contentOffset: {0, 0}; contentSize: {0, 0}; adjustedContentInset: {0, 0, 291, 0}; dataSource: (null)>
2021-05-11 15:36:38.176338+0800 App-Beta[1141:430280] [Assert] Unsupported use of UIKit view-customization API off the main thread. -setSeparatorColor: sent to <UIPickerTableView: 0x105ab2800; frame = (31 -37.6667; 103 291); clipsToBounds = YES; gestureRecognizers = <NSArray: 0x2811fc4b0>; layer = <CALayer: 0x281e0ed60>; contentOffset: {0, 0}; contentSize: {0, 0}; adjustedContentInset: {0, 0, 291, 0}; dataSource: (null)>
2021-05-11 15:36:38.177102+0800 App-Beta[1141:430280] [Assert] Unsupported use of UIKit view-customization API off the main thread. -setSeparatorStyle: sent to <UIPickerTableView: 0x105ab2800; frame = (31 -37.6667; 103 291); clipsToBounds = YES; gestureRecognizers = <NSArray: 0x2811fc4b0>; layer = <CALayer: 0x281e0ed60>; contentOffset: {0, 0}; contentSize: {0, 0}; adjustedContentInset: {0, 0, 291, 0}; dataSource: (null)>
...
2021-05-11 15:36:38.257101+0800 App-Beta[1141:430280] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Modifications to the layout engine must not be performed from a background thread after it has been accessed from the main thread.'
...
从上面的报错可以看出是由于更新UI不在主线程中导致的。
解决方法也很简单,即把报错的代码放到主队列中执行:
- Modern Swift:
DispatchQueue.main.async {
// Update UI
}
- Older versions of Swift, pre Swift 3.
dispatch_async(dispatch_get_main_queue(){
// code here
})
- Objective-C:
dispatch_async(dispatch_get_main_queue(), ^{
// code here
});
参考:Getting a “This application is modifying the autolayout engine from a background thread” error?
最后
以上就是鲤鱼狗为你收集整理的iOS 13 报错:[Assert] Unsupported use of UIKit view-customization API off the main thread的全部内容,希望文章能够帮你解决iOS 13 报错:[Assert] Unsupported use of UIKit view-customization API off the main thread所遇到的程序开发问题。
如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复