我们的应用程序使用 CoreNFC 扫描 NFC 标签,如果不支持 NFC,您可以使用 QR。这工作得很好,我们能够在模拟器中运行应用程序以进行(ui)测试。
直到 Xcode12 / iOS14 GM 构建。在 iOS13(或更低版本)中,我们在模拟器上运行它不会有任何问题。
但是在 Xcode12 中,在 iOS14 模拟器 iPhone11 上运行它,我们会得到以下结果:
dyld: launch, loading dependent libraries
DYLD_SHARED_CACHE_DIR=/Users/xxx/Library/Developer/CoreSimulator/Caches/dyld/19G73/com.apple.CoreSimulator.SimRuntime.iOS-14-0.18A372
DYLD_ROOT_PATH=/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Library/Developer/CoreSimulator/Profiles/Runtimes/iOS.simruntime/Contents/Resources/RuntimeRoot
DYLD_LIBRARY_PATH=/Users/xxx/Library/Developer/Xcode/DerivedData/xxx-awnlestrbvesqqbynrhmluzhbcsc/Build/Products/Debug-iphonesimulator:/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Library/Developer/CoreSimulator/Profiles/Runtimes/iOS.simruntime/Contents/Resources/RuntimeRoot/usr/lib/system/introspection
DYLD_INSERT_LIBRARIES=/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Library/Developer/CoreSimulator/Profiles/Runtimes/iOS.simruntime/Contents/Resources/RuntimeRoot/usr/lib/libBacktraceRecording.dylib:/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Library/Developer/CoreSi
dyld: Library not loaded: /usr/lib/libnfshared.dylib
Referenced from: /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Library/Developer/CoreSimulator/Profiles/Runtimes/iOS.simruntime/Contents/Resources/RuntimeRoot/System/Library/Frameworks/CoreNFC.framework/CoreNFC
Reason: no suitable image found. Did find:
/usr/lib/libnfshared.dylib: mach-o, but not built for platform iOS-sim
模拟器崩溃对我来说很有意义,因为模拟器无法扫描 NFC 标签,但这就是我所做的:
- 我已经链接到 CoreNFC 框架并使其成为可选,如下所述:Xcode 10, Swift 4 app with CoreNFC crash in review on iOS 12
- 放一放
#if canImport(CoreNFC)
,import CoreNFC
它是底层的 NFC 代码。 - 清理构建文件夹并删除派生数据。
- 创建了一个空的 Xcode12 项目:https ://github.com/basvankuijck/CoreNFCCrashProject ,结果相同。
- 删除了所有列出的模拟器并重新添加了一个
- 添加
-weak_framework "CoreNFC"
到其他链接器标志构建设置
显然,通过注释掉代码部分并删除框架链接来删除对 CoreNFC 框架的任何引用,会使崩溃消失。但这不是一个合适的选择。
在 iOS13 模拟器“设备”上从 Xcode12 运行它可以完美运行。所以我似乎无法弄清楚是什么导致了这种行为