ios - iOS / MacOS 内容过滤 API WKContentRuleListStore compileContentRuleList 是否需要在主线程上调用?获取 EXC_BREAKPOINT
问题描述
在之前的 iOS 13 和 macOS Catalina 中,以下代码运行良好:
WKContentRuleListStore.default().compileContentRuleList(forIdentifier: "MYID", encodedContentRuleList: jsonFileContent) { (contentRuleList, error) in
if let error = error {
print("COMPILE ERROR: \(error)")
return
}
if let list = contentRuleList {
//print("GOT BLOCK LIST!")
blockList = list
}
}
但是在 iOS 14 和 Big Sur 中,这个崩溃EXC_BREAKPOINT
也出现在另一个 SO 帖子中:
iOS 14 中的 WKContentRuleListStore.default() 崩溃
在 MacOS 上,它会崩溃:
Crashed Thread: 1 Dispatch queue: com.apple.NSURLSession-delegate
Exception Type: EXC_BREAKPOINT (SIGTRAP)
Exception Codes: 0x0000000000000002, 0x0000000000000000
Exception Note: EXC_CORPSE_NOTIFY
Termination Signal: Trace/BPT trap: 5
Termination Reason: Namespace SIGNAL, Code 0x5
Terminating Process: exc handler [2768]
Thread 1 Crashed:: Dispatch queue: com.apple.NSURLSession-delegate
0 com.apple.WebKit 0x00007fff3c5fc293 WTFCrashWithInfo(int, char const*, char const*, int) + 19
1 com.apple.WebKit 0x00007fff3c79aaa3 WebKit::runInitializationCode(void*) + 73
2 libc++.1.dylib 0x00007fff20313e6a std::__1::__call_once(unsigned long volatile&, void*, void (*)(void*)) + 139
3 com.apple.WebKit 0x00007fff3c5a00fe WebKit::InitializeWebKit2() + 58
4 com.apple.WebKit 0x00007fff3c9be8e6 API::ContentRuleListStore::ContentRuleListStore(WTF::String const&, bool) + 44
5 com.apple.WebKit 0x00007fff3c9be83c API::ContentRuleListStore::ContentRuleListStore(bool) + 48
6 com.apple.WebKit 0x00007fff3c9be8a0 API::ContentRuleListStore::nonLegacyDefaultStore() + 60
7 com.apple.WebKit 0x00007fff3c831641 +[WKContentRuleListStore defaultStore] + 9
8 com.example.XXX 0x0000000107ebd2d0 closure #1 in getBlockList() + 1024 (AppDelegate.swift:1772)
9 com.example.XXX 0x0000000107ea3928 thunk for @escaping @callee_guaranteed (@guaranteed Data?, @guaranteed NSURLResponse?, @guaranteed Error?) -> () + 296
10 com.apple.CFNetwork 0x00007fff24780a5e 0x7fff246bc000 + 805470
11 com.apple.CFNetwork 0x00007fff246dae08 0x7fff246bc000 + 126472
12 libdispatch.dylib 0x00007fff201d25dd _dispatch_call_block_and_release + 12
13 libdispatch.dylib 0x00007fff201d37c7 _dispatch_client_callout + 8
14 libdispatch.dylib 0x00007fff201d95fe _dispatch_lane_serial_drain + 606
15 libdispatch.dylib 0x00007fff201da0fe _dispatch_lane_invoke + 426
16 libdispatch.dylib 0x00007fff201e3c5d _dispatch_workloop_worker_thread + 819
17 libsystem_pthread.dylib 0x00007fff2037b499 _pthread_wqthread + 314
18 libsystem_pthread.dylib 0x00007fff2037a467 start_wqthread + 15
在主线程上运行代码可以解决问题:
DispatchQueue.main.async {
WKContentRuleListStore.default().compileContentRuleList(forIdentifier: "MYID", encodedContentRuleList: jsonFileContent) { (contentRuleList, error) in
if let error = error {
print("COMPILE ERROR: \(error)")
return
}
if let list = contentRuleList {
//print("GOT BLOCK LIST!")
blockList = list
}
}
}
SDK 最近有变化吗?错误消息甚至没有像 Xcode 通常那样提及或给出任何主线程警告。而且我似乎找不到任何说明它必须在主线程上运行的文档。
解决方案
推荐阅读
- java - char 数组和替换单词的问题
- node.js - 如何使用自己的 Gruntfile.js 合并 2 个应用程序并拥有自己的 package.json
- javascript - 基于多维数组的第二个值进行验证
- ubuntu - Dymola 图表视图中缺少连接
- javascript - 在两个谷歌饼图中只有一个被显示
- c# - 是否可以使用 C# 以编程方式将 bacpac/bak 从 blob 存储还原到 azure sql
- python - 从 SQLAlchemy 查询中获取第二行
- c# - 如何为 Application Insights Log4Net Appender 设置遥测通道?
- javascript - 当关联类有多个实例时,javascript 行为不端
- tensorflow - 如何在层中冻结一个过滤器,同时保持其他过滤器可训练?