为什么用结构调用对话框会丢弃此异常?
Why calling a dialog with a struct drops this exception?
我正在尝试重定向在结构中解码的此 API 调用的输出,但是当我尝试使用数据创建对话框时,它给了我这个奇怪的异常。如您所见,API returns 数据但仅当我创建对话框时我才看到此异常。你能帮帮我吗?
代码:
struct rspServerInfo: Codable{
let ok: Bool
let info: String
}
@IBAction func backendDetails(_ sender: Any) {
guard let url = URL(string: "http://\(hostname):\(port)/STOInfo/ServerInfo")else{
return
}
var request = URLRequest(url: url)
request.httpMethod = "POST"
request.setValue("application/json", forHTTPHeaderField: "Content-Type")
let body: [String: AnyHashable] = [
"username": username,
"password": password,
]
request.httpBody = try? JSONSerialization.data(withJSONObject: body, options: .fragmentsAllowed)
let task = URLSession.shared.dataTask(with: request) {data, _, error in
guard let data=data, error == nil else{
return
}
do{
let response = try JSONDecoder().decode(rspServerInfo.self, from: data)
print("SUCCESS: \(response)")
let dialogMessage = UIAlertController(title: "Backend details", message: response.info, preferredStyle: .alert)
let ok = UIAlertAction(title: "OK", style: .default, handler: { (action) -> Void in
print("Ok button tapped")
})
dialogMessage.addAction(ok)
self.present(dialogMessage, animated: true, completion: nil)
}
catch{
print(error)
let dialogMessage = UIAlertController(title: "Backend details", message: "Error retreiving.", preferredStyle: .alert)
let ok = UIAlertAction(title: "OK", style: .default, handler: { (action) -> Void in
print("Ok button tapped")
})
dialogMessage.addAction(ok)
self.present(dialogMessage, animated: true, completion: nil)
}
}
task.resume()
}
异常:
成功:rspServerInfo(确定:正确,信息:“STO 后端 alpha 1.0”)
2022-04-13 18:13:05.599263+0200 ServiceTOOLS Control[1843:69401] [断言] 无法在非主线程上使用 asCopy = NO 调用。
2022-04-13 18:13:05.600031+0200 ServiceTOOLS Control[1843:69401] [断言] 无法在非主线程上使用 asCopy = NO 调用。
2022-04-13 18:13:05.604952+0200 ServiceTOOLS Control[1843:69401] [断言] 无法在非主线程上使用 asCopy = NO 调用。
2022-04-13 18:13:05.605543+0200 ServiceTOOLS Control[1843:69401] [断言] 无法在非主线程上使用 asCopy = NO 调用。
2022-04-13 18:13:05.605700+0200 ServiceTOOLS Control[1843:69401] [断言] 无法在非主线程上使用 asCopy = NO 调用。
2022-04-13 18:13:05.605882+0200 ServiceTOOLS Control[1843:69401] [断言] 无法在非主线程上使用 asCopy = NO 调用。
2022-04-13 18:13:05.606270+0200 ServiceTOOLS Control[1843:69401] [断言] 无法在非主线程上使用 asCopy = NO 调用。
2022-04-13 18:13:05.606668+0200 ServiceTOOLS Control[1843:69401] [断言] 无法在非主线程上使用 asCopy = NO 调用。
2022-04-13 18:13:05.606785+0200 ServiceTOOLS Control[1843:69401] [断言] 无法在非主线程上使用 asCopy = NO 调用。
2022-04-13 18:13:05.606909+0200 ServiceTOOLS Control[1843:69401] [断言] 无法在非主线程上使用 asCopy = NO 调用。
2022-04-13 18:13:05.607200+0200 ServiceTOOLS Control[1843:69401] [断言] 无法在非主线程上使用 asCopy = NO 调用。
2022-04-13 18:13:05.607559+0200 ServiceTOOLS Control[1843:69401] [断言] 无法在非主线程上使用 asCopy = NO 调用。
2022-04-13 18:13:05.608617+0200 ServiceTOOLS Control[1843:69401] [断言] 无法在非主线程上使用 asCopy = NO 调用。
2022-04-13 18:13:05.609164+0200 ServiceTOOLS Control[1843:69401] [断言] 无法在非主线程上使用 asCopy = NO 调用。
2022-04-13 18:13:05.609516+0200 ServiceTOOLS Control[1843:69401] [断言] 无法在非主线程上使用 asCopy = NO 调用。
2022-04-13 18:13:05.609899+0200 ServiceTOOLS Control[1843:69401] [断言] 无法在非主线程上使用 asCopy = NO 调用。
2022-04-13 18:13:05.610557+0200 ServiceTOOLS Control[1843:69401] [Assert] 无法在非主线程上使用 asCopy = NO 调用。
2022-04-13 18:13:05.610983+0200 ServiceTOOLS Control[1843:69401] [断言] 无法在非主线程上使用 asCopy = NO 调用。
2022-04-13 18:13:05.611178+0200 ServiceTOOLS Control[1843:69401] [断言] 无法在非主线程上使用 asCopy = NO 调用。
2022-04-13 18:13:05.624518+0200 ServiceTOOLS Control[1843:69401] [Animation] +[UIView setAnimationsEnabled:] 从后台线程调用。不支持从后台线程对 UIView 或子类执行任何操作,这可能会导致意外和隐蔽的行为。踪迹=(
0 UIKitCore 0x00000001843d8514 E9BCC2B0-AD59-3D23-87B4-495ABEDF5730 + 18552084
1 libdispatch.dylib 0x000000010077dfc8 _dispatch_client_callout + 16
2 libdispatch.dylib 0x000000010077f934 dispatch_once_callout + 80
3 UIKitCore 0x0000000183389c74 E9BCC2B0-AD59-3D23-87B4-495ABEDF5730 + 1453172
4 UIKitCore 0x00000001837ce078 E9BCC2B0-AD59-3D23-87B4-495ABEDF5730 + 5927032
5 UIKitCore 0x00000001834f5424 E9BCC2B0-AD59-3D23-87B4-495ABEDF5730 + 2941988
6 UIKitCore 0x00000001837e7f34 E9BCC2B0-AD59-3D23-87B4-495ABEDF5730 + 6033204
7 UIKitCore 0x000000018382dba4 E9BCC2B0-AD59-3D23-87B4-495ABEDF5730 + 6319012
8 UIKitCore 0x0000000183882b20 E9BCC2B0-AD59-3D23-87B4-495ABEDF5730 + 6667040
9 UIKitCore 0x00000001837390cc E9BCC2B0-AD59-3D23-87B4-495ABEDF5730 + 5316812
10 UIKitCore 0x00000001832516d4 E9BCC2B0-AD59-3D23-87B4-495ABEDF5730 + 173780
11 UIKitCore 0x000000018335a524 E9BCC2B0-AD59-3D23-87B4-495ABEDF5730 + 1258788
12 UIKitCore 0x000000018376fd74 E9BCC2B0-AD59-3D23-87B4-495ABEDF5730 + 5541236
13 UIKitCore 0x000000018379541c E9BCC2B0-AD59-3D23-87B4-495ABEDF5730 + 5694492
14 UIKitCore 0x0000000183617a20 E9BCC2B0-AD59-3D23-87B4-495ABEDF5730 + 4131360
15 UIKitCore 0x000000018376b980 E9BCC2B0-AD59-3D23-87B4-495ABEDF5730 + 5523840
16 UIKitCore 0x00000001833c3a44 E9BCC2B0-AD59-3D23-87B4-495ABEDF5730 + 1690180
17 UIKitCore 0x00000001833987c8 E9BCC2B0-AD59-3D23-87B4-495ABEDF5730 + 1513416
18 UIKitCore 0x000000018355b0b0 E9BCC2B0-AD59-3D23-87B4-495ABEDF5730 + 3358896
19 UIKitCore 0x000000018360f4bc E9BCC2B0-AD59-3D23-87B4-495ABEDF5730 + 4097212
20 UIKitCore 0x00000001836c9c0c E9BCC2B0-AD59-3D23-87B4-495ABEDF5730 + 4860940
21 UIKitCore 0x00000001834cb638 E9BCC2B0-AD59-3D23-87B4-495ABEDF5730 + 2770488
22 UIKitCore 0x000000018346c5c8 E9BCC2B0-AD59-3D23-87B4-495ABEDF5730 + 2381256
23 UIKitCore 0x00000001835d289c E9BCC2B0-AD59-3D23-87B4-495ABEDF5730 + 3848348
24 UIKitCore 0x00000001834eeea4 E9BCC2B0-AD59-3D23-87B4-495ABEDF5730 + 2916004
25 服务工具控制 0x0000000100435320 $s20ServiceTOOLS_Control14ViewControllerC14backendDetailsyyypFy10Foundation4DataVSg_So13NSURLResponseCSgs5Error_pSgtcfU + 1072
26 服务工具控制 0x0000000100435854 $s10Foundation4DataVSgSo13NSURLResponseCSgs5Error_pSgIegggg_So6NSDataCSgAGSo7NSErrorCSgIeyByyy_TR + 268
27 CFNetwork 0x00000001816ebb9c CFURLRequestSetMainDocumentURL + 2496
28 CF网络 0x00000001816fc210 _CFNetworkErrorCopyLocalizedDescriptionWithHostname + 11296
29 libdispatch.dylib 0x000000010077c700 _dispatch_call_block_and_release + 24
30 libdispatch.dylib 0x000000010077dfc8 _dispatch_client_callout + 16
31 libdispatch.dylib 0x0000000100785150 _dispatch_lane_serial_drain + 684
32 libdispatch.dylib 0x0000000100785e10 _dispatch_lane_invoke + 484
33 libdispatch.dylib 0x000000010079163c _dispatch_workloop_worker_thread + 852
34 libsystem_pthread.dylib 0x00000001dc87de10 _pthread_wqthread + 284
35 libsystem_pthread.dylib 0x00000001dc87d93c start_wqthread + 8
)
2022-04-13 18:13:05.636837+0200 ServiceTOOLS Control[1843:69401] [断言] 不支持在主线程外使用 UIKit 视图自定义 API。 -setHasDimmingView: 发送到 <_UIAlertControllerView: 0x12bd46690;帧 = (0 0; 320 568);层 = >
2022-04-13 18:13:05.637270+0200 ServiceTOOLS Control[1843:69401] [断言] 不支持在主线程外使用 UIKit 视图自定义 API。 -setShouldHaveBackdropView: 发送到 <_UIAlertControllerView: 0x12bd46690;帧 = (0 0; 320 568);层 = >
2022-04-13 18:13:05.637433+0200 ServiceTOOLS Control[1843:69401] [断言] 无法在非主线程上使用 asCopy = NO 调用。
2022-04-13 18:13:05.637616+0200 ServiceTOOLS Control[1843:69401] [断言] 不支持在主线程外使用 UIKit 视图自定义 API。 -setAlignsToKeyboard:发送到<UIAlertControllerView:0x12bd46690;帧 = (0 0; 320 568);层 = >
2022-04-13 18:13:05.640311+0200 ServiceTOOLS Control[1843:69401] [断言] 无法在非主线程上使用 asCopy = NO 调用。
2022-04-13 18:13:05.645960+0200 ServiceTOOLS Control[1843:69401] 从主线程访问引擎后,此应用程序正在从后台线程修改自动布局引擎。这可能导致引擎损坏和奇怪的崩溃。
堆:(
0 CoreAutoLayout 0x0000000198f94f20 E21B6C11-F8B8-3259-8A95-9836F586EA21 + 20256
1 CoreAutoLayout 0x0000000198f97b7c E21B6C11-F8B8-3259-8A95-9836F586EA21 + 31612
2 UIKitCore 0x000000018359caf4 E9BCC2B0-AD59-3D23-87B4-495ABEDF5730 + 3627764
3 UIKitCore 0x000000018353b724 E9BCC2B0-AD59-3D23-87B4-495ABEDF5730 + 3229476
4 UIKitCore 0x000000018370f810 E9BCC2B0-AD59-3D23-87B4-495ABEDF5730 + 5146640
5 UIKitCore 0x000000018331a394 E9BCC2B0-AD59-3D23-87B4-495ABEDF5730 + 996244
6 UIKitCore 0x000000018331a084 E9BCC2B0-AD59-3D23-87B4-495ABEDF5730 + 995460
7 UIKitCore 0x0000000183318a00 E9BCC2B0-AD59-3D23-87B4-495ABEDF5730 + 989696
8 UIKitCore 0x00000001836f7dac E9BCC2B0-AD59-3D23-87B4-495ABEDF5730 + 5049772
9 UIKitCore 0x00000001838530d0 E9BCC2B0-AD59-3D23-87B4-495ABEDF5730 + 6471888
10 UIKitCore 0x000000018376ba8c E9BCC2B0-AD59-3D23-87B4-495ABEDF5730 + 5524108
11 UIKitCore 0x00000001833c3a44 E9BCC2B0-AD59-3D23-87B4-495ABEDF5730 + 1690180
12 UIKitCore 0x00000001833987c8 E9BCC2B0-AD59-3D23-87B4-495ABEDF5730 + 1513416
13 UIKitCore 0x000000018355b0b0 E9BCC2B0-AD59-3D23-87B4-495ABEDF5730 + 3358896
14 UIKitCore 0x000000018360f4bc E9BCC2B0-AD59-3D23-87B4-495ABEDF5730 + 4097212
15 UIKitCore 0x00000001836c9c0c E9BCC2B0-AD59-3D23-87B4-495ABEDF5730 + 4860940
16 UIKitCore 0x00000001834cb638 E9BCC2B0-AD59-3D23-87B4-495ABEDF5730 + 2770488
17 UIKitCore 0x000000018346c5c8 E9BCC2B0-AD59-3D23-87B4-495ABEDF5730 + 2381256
18 UIKitCore 0x00000001835d289c E9BCC2B0-AD59-3D23-87B4-495ABEDF5730 + 3848348
19 UIKitCore 0x00000001834eeea4 E9BCC2B0-AD59-3D23-87B4-495ABEDF5730 + 2916004
20 服务工具控制 0x0000000100435320 $s20ServiceTOOLS_Control14ViewControllerC14backendDetailsyyypFy10Foundation4DataVSg_So13NSURLResponseCSgs5Error_pSgtcfU + 1072
21 服务工具控制 0x0000000100435854 $s10Foundation4DataVSgSo13NSURLResponseCSgs5Error_pSgIegggg_So6NSDataCSgAGSo7NSErrorCSgIeyByyy_TR + 268
22 CFNetwork 0x00000001816ebb9c CFURLRequestSetMainDocumentURL + 2496
23 CFNetwork 0x00000001816fc210 _CFNetworkErrorCopyLocalizedDescriptionWithHostname + 11296
24 libdispatch.dylib 0x000000010077c700 _dispatch_call_block_and_release + 24
25 libdispatch.dylib 0x000000010077dfc8 _dispatch_client_callout + 16
26 libdispatch.dylib 0x0000000100785150 _dispatch_lane_serial_drain + 684
27 libdispatch.dylib 0x0000000100785e10 _dispatch_lane_invoke + 484
28 libdispatch.dylib 0x000000010079163c _dispatch_workloop_worker_thread + 852
29 libsystem_pthread.dylib 0x00000001dc87de10 _pthread_wqthread + 284
30 libsystem_pthread.dylib 0x00000001dc87d93c start_wqthread + 8
)
2022-04-13 18:13:05.647262+0200 ServiceTOOLS Control[1843:69401] *** 由于未捕获的异常 'NSInternalInconsistencyException' 而终止应用程序,原因:'Modifications to the layout engine must not be performed from a background thread after it has been accessed from the main thread.'
*** 首先抛出调用栈:
(0x180f83e0c 0x198cd2ee4 0x198f95000 0x198f97b7c 0x18359caf4 0x18353b724 0x18370f810 0x18331a394 0x18331a084 0x183318a00 0x1836f7dac 0x1838530d0 0x18376ba8c 0x1833c3a44 0x1833987c8 0x18355b0b0 0x18360f4bc 0x1836c9c0c 0x1834cb638 0x18346c5c8 0x1835d289c 0x1834eeea4 0x100435320 0x100435854 0x1816ebb9c 0x1816fc210 0x10077c700 0x10077dfc8 0x100785150 0x100785e10 0x10079163c 0x1dc87de10 0x1dc87d93c)
libc++abi:以 NSException 类型的未捕获异常终止
dyld4配置:DYLD_LIBRARY_PATH=/usr/lib/system/introspection DYLD_INSERT_LIBRARIES=/Developer/usr/lib/libBacktraceRecording.dylib:/Developer/usr/lib/libMainThreadChecker.dylib:/Developer/Library/PrivateFrameworks/DTDDISupport.framework/libViewDebuggerSupport.dylib
*** 由于未捕获的异常 'NSInternalInconsistencyException' 而终止应用程序,原因:'Modifications to the layout engine must not be performed from a background thread after it has been accessed from the main thread.'
以 NSException
类型的未捕获异常终止
报错信息给出了一个大线索:
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.' terminating with uncaught
exception of type NSException
URLRequest 运行 在后台线程上异步执行,包括其完成处理程序。你(通常)不能在主线程之外做 UI 工作。要显示结果,您需要将操作推回主线程:
DispatchQueue.main.async {
// do UI work
}
我正在尝试重定向在结构中解码的此 API 调用的输出,但是当我尝试使用数据创建对话框时,它给了我这个奇怪的异常。如您所见,API returns 数据但仅当我创建对话框时我才看到此异常。你能帮帮我吗?
代码:
struct rspServerInfo: Codable{
let ok: Bool
let info: String
}
@IBAction func backendDetails(_ sender: Any) {
guard let url = URL(string: "http://\(hostname):\(port)/STOInfo/ServerInfo")else{
return
}
var request = URLRequest(url: url)
request.httpMethod = "POST"
request.setValue("application/json", forHTTPHeaderField: "Content-Type")
let body: [String: AnyHashable] = [
"username": username,
"password": password,
]
request.httpBody = try? JSONSerialization.data(withJSONObject: body, options: .fragmentsAllowed)
let task = URLSession.shared.dataTask(with: request) {data, _, error in
guard let data=data, error == nil else{
return
}
do{
let response = try JSONDecoder().decode(rspServerInfo.self, from: data)
print("SUCCESS: \(response)")
let dialogMessage = UIAlertController(title: "Backend details", message: response.info, preferredStyle: .alert)
let ok = UIAlertAction(title: "OK", style: .default, handler: { (action) -> Void in
print("Ok button tapped")
})
dialogMessage.addAction(ok)
self.present(dialogMessage, animated: true, completion: nil)
}
catch{
print(error)
let dialogMessage = UIAlertController(title: "Backend details", message: "Error retreiving.", preferredStyle: .alert)
let ok = UIAlertAction(title: "OK", style: .default, handler: { (action) -> Void in
print("Ok button tapped")
})
dialogMessage.addAction(ok)
self.present(dialogMessage, animated: true, completion: nil)
}
}
task.resume()
}
异常:
成功:rspServerInfo(确定:正确,信息:“STO 后端 alpha 1.0”)
2022-04-13 18:13:05.599263+0200 ServiceTOOLS Control[1843:69401] [断言] 无法在非主线程上使用 asCopy = NO 调用。
2022-04-13 18:13:05.600031+0200 ServiceTOOLS Control[1843:69401] [断言] 无法在非主线程上使用 asCopy = NO 调用。
2022-04-13 18:13:05.604952+0200 ServiceTOOLS Control[1843:69401] [断言] 无法在非主线程上使用 asCopy = NO 调用。
2022-04-13 18:13:05.605543+0200 ServiceTOOLS Control[1843:69401] [断言] 无法在非主线程上使用 asCopy = NO 调用。
2022-04-13 18:13:05.605700+0200 ServiceTOOLS Control[1843:69401] [断言] 无法在非主线程上使用 asCopy = NO 调用。
2022-04-13 18:13:05.605882+0200 ServiceTOOLS Control[1843:69401] [断言] 无法在非主线程上使用 asCopy = NO 调用。
2022-04-13 18:13:05.606270+0200 ServiceTOOLS Control[1843:69401] [断言] 无法在非主线程上使用 asCopy = NO 调用。
2022-04-13 18:13:05.606668+0200 ServiceTOOLS Control[1843:69401] [断言] 无法在非主线程上使用 asCopy = NO 调用。
2022-04-13 18:13:05.606785+0200 ServiceTOOLS Control[1843:69401] [断言] 无法在非主线程上使用 asCopy = NO 调用。
2022-04-13 18:13:05.606909+0200 ServiceTOOLS Control[1843:69401] [断言] 无法在非主线程上使用 asCopy = NO 调用。
2022-04-13 18:13:05.607200+0200 ServiceTOOLS Control[1843:69401] [断言] 无法在非主线程上使用 asCopy = NO 调用。
2022-04-13 18:13:05.607559+0200 ServiceTOOLS Control[1843:69401] [断言] 无法在非主线程上使用 asCopy = NO 调用。
2022-04-13 18:13:05.608617+0200 ServiceTOOLS Control[1843:69401] [断言] 无法在非主线程上使用 asCopy = NO 调用。
2022-04-13 18:13:05.609164+0200 ServiceTOOLS Control[1843:69401] [断言] 无法在非主线程上使用 asCopy = NO 调用。
2022-04-13 18:13:05.609516+0200 ServiceTOOLS Control[1843:69401] [断言] 无法在非主线程上使用 asCopy = NO 调用。
2022-04-13 18:13:05.609899+0200 ServiceTOOLS Control[1843:69401] [断言] 无法在非主线程上使用 asCopy = NO 调用。
2022-04-13 18:13:05.610557+0200 ServiceTOOLS Control[1843:69401] [Assert] 无法在非主线程上使用 asCopy = NO 调用。
2022-04-13 18:13:05.610983+0200 ServiceTOOLS Control[1843:69401] [断言] 无法在非主线程上使用 asCopy = NO 调用。
2022-04-13 18:13:05.611178+0200 ServiceTOOLS Control[1843:69401] [断言] 无法在非主线程上使用 asCopy = NO 调用。
2022-04-13 18:13:05.624518+0200 ServiceTOOLS Control[1843:69401] [Animation] +[UIView setAnimationsEnabled:] 从后台线程调用。不支持从后台线程对 UIView 或子类执行任何操作,这可能会导致意外和隐蔽的行为。踪迹=(
0 UIKitCore 0x00000001843d8514 E9BCC2B0-AD59-3D23-87B4-495ABEDF5730 + 18552084
1 libdispatch.dylib 0x000000010077dfc8 _dispatch_client_callout + 16
2 libdispatch.dylib 0x000000010077f934 dispatch_once_callout + 80
3 UIKitCore 0x0000000183389c74 E9BCC2B0-AD59-3D23-87B4-495ABEDF5730 + 1453172
4 UIKitCore 0x00000001837ce078 E9BCC2B0-AD59-3D23-87B4-495ABEDF5730 + 5927032
5 UIKitCore 0x00000001834f5424 E9BCC2B0-AD59-3D23-87B4-495ABEDF5730 + 2941988
6 UIKitCore 0x00000001837e7f34 E9BCC2B0-AD59-3D23-87B4-495ABEDF5730 + 6033204
7 UIKitCore 0x000000018382dba4 E9BCC2B0-AD59-3D23-87B4-495ABEDF5730 + 6319012
8 UIKitCore 0x0000000183882b20 E9BCC2B0-AD59-3D23-87B4-495ABEDF5730 + 6667040
9 UIKitCore 0x00000001837390cc E9BCC2B0-AD59-3D23-87B4-495ABEDF5730 + 5316812
10 UIKitCore 0x00000001832516d4 E9BCC2B0-AD59-3D23-87B4-495ABEDF5730 + 173780
11 UIKitCore 0x000000018335a524 E9BCC2B0-AD59-3D23-87B4-495ABEDF5730 + 1258788
12 UIKitCore 0x000000018376fd74 E9BCC2B0-AD59-3D23-87B4-495ABEDF5730 + 5541236
13 UIKitCore 0x000000018379541c E9BCC2B0-AD59-3D23-87B4-495ABEDF5730 + 5694492
14 UIKitCore 0x0000000183617a20 E9BCC2B0-AD59-3D23-87B4-495ABEDF5730 + 4131360
15 UIKitCore 0x000000018376b980 E9BCC2B0-AD59-3D23-87B4-495ABEDF5730 + 5523840
16 UIKitCore 0x00000001833c3a44 E9BCC2B0-AD59-3D23-87B4-495ABEDF5730 + 1690180
17 UIKitCore 0x00000001833987c8 E9BCC2B0-AD59-3D23-87B4-495ABEDF5730 + 1513416
18 UIKitCore 0x000000018355b0b0 E9BCC2B0-AD59-3D23-87B4-495ABEDF5730 + 3358896
19 UIKitCore 0x000000018360f4bc E9BCC2B0-AD59-3D23-87B4-495ABEDF5730 + 4097212
20 UIKitCore 0x00000001836c9c0c E9BCC2B0-AD59-3D23-87B4-495ABEDF5730 + 4860940
21 UIKitCore 0x00000001834cb638 E9BCC2B0-AD59-3D23-87B4-495ABEDF5730 + 2770488
22 UIKitCore 0x000000018346c5c8 E9BCC2B0-AD59-3D23-87B4-495ABEDF5730 + 2381256
23 UIKitCore 0x00000001835d289c E9BCC2B0-AD59-3D23-87B4-495ABEDF5730 + 3848348
24 UIKitCore 0x00000001834eeea4 E9BCC2B0-AD59-3D23-87B4-495ABEDF5730 + 2916004
25 服务工具控制 0x0000000100435320 $s20ServiceTOOLS_Control14ViewControllerC14backendDetailsyyypFy10Foundation4DataVSg_So13NSURLResponseCSgs5Error_pSgtcfU + 1072
26 服务工具控制 0x0000000100435854 $s10Foundation4DataVSgSo13NSURLResponseCSgs5Error_pSgIegggg_So6NSDataCSgAGSo7NSErrorCSgIeyByyy_TR + 268
27 CFNetwork 0x00000001816ebb9c CFURLRequestSetMainDocumentURL + 2496
28 CF网络 0x00000001816fc210 _CFNetworkErrorCopyLocalizedDescriptionWithHostname + 11296
29 libdispatch.dylib 0x000000010077c700 _dispatch_call_block_and_release + 24
30 libdispatch.dylib 0x000000010077dfc8 _dispatch_client_callout + 16
31 libdispatch.dylib 0x0000000100785150 _dispatch_lane_serial_drain + 684
32 libdispatch.dylib 0x0000000100785e10 _dispatch_lane_invoke + 484
33 libdispatch.dylib 0x000000010079163c _dispatch_workloop_worker_thread + 852
34 libsystem_pthread.dylib 0x00000001dc87de10 _pthread_wqthread + 284
35 libsystem_pthread.dylib 0x00000001dc87d93c start_wqthread + 8
)
2022-04-13 18:13:05.636837+0200 ServiceTOOLS Control[1843:69401] [断言] 不支持在主线程外使用 UIKit 视图自定义 API。 -setHasDimmingView: 发送到 <_UIAlertControllerView: 0x12bd46690;帧 = (0 0; 320 568);层 =
报错信息给出了一个大线索:
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.' terminating with uncaught exception of type NSException
URLRequest 运行 在后台线程上异步执行,包括其完成处理程序。你(通常)不能在主线程之外做 UI 工作。要显示结果,您需要将操作推回主线程:
DispatchQueue.main.async {
// do UI work
}