![](/img/trans.png)
[英]Xcode 9.0 Swift 04 (Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Only run on the main thread!')
[英]Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'threading violation: expected the main thread'
我的应用程序正在使用第三方库,并且在某些设备(例如 iOS 13.3)上发生崩溃
尝试在主线程上调用该方法
主线程检查器:在后台线程上调用的 UI API:-[UIApplication statusBarOrientation] PID:1496,TID:390696,线程名称:(无),队列名称:com.apple.root.default-qos.overcommit,QoS:0
2020-01-28 12:31:47.733875+0000 My BT Gotham[1496:390696] *** 由于未捕获的异常“NSInternalInconsistencyException”而终止应用程序,原因:“线程违规:预期主线程”
尝试在后台线程上调用该方法
这是错误
- -[FBSSerialQueue assertOnQueue] 中的断言失败,/BuildRoot/Library/Caches/com.apple.xbs/Sources/FrontBoardServices/FrontBoard-626.4.1/FrontBoardServices/FBSSerialQueue.m:98 2020-01-28 17:272347.2 0000 我的 BT Gotham[1773:459656] *** 由于未捕获的异常“NSInternalInconsistencyException”而终止应用程序,原因:“线程违规:预期主线程”
仅供参考:我总是在后台线程上使用 API 方法,它在大多数设备中都可以正常工作,我上面引用的问题仅在某些设备中有效。
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^(void){
[LibObj model_Method:self];
});
看起来,您正在从后台调用 UI 方法......它应该是这样的:
DispatchQueue.main.async {
// use your method...
}
但是,如果您的第三方库已经在幕后进行 DispatchQueue.main 调用,那么当您进行异步调用时,它可能会变得一团糟......
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.