我是靠谱客的博主 鲤鱼狗,这篇文章主要介绍iOS 13 报错:[Assert] Unsupported use of UIKit view-customization API off the main thread,现在分享给大家,希望可以做个参考。
萤石摄像头回看,在iOS 11上运行好好,在iOS 13上却报错了,报错如下:
复制代码
1
2
3
4
5
6
7
82021-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:
复制代码
1
2
3
4DispatchQueue.main.async { // Update UI }
- Older versions of Swift, pre Swift 3.
复制代码
1
2
3
4dispatch_async(dispatch_get_main_queue(){ // code here })
- Objective-C:
复制代码
1
2
3
4dispatch_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内容请搜索靠谱客的其他文章。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复