我们的应用程序使用 CoreNFC 来扫描 NFC 标签,如果不支持 NFC,您可以使用 QR。这工作得很好,我们能够在模拟器中运行该应用程序以进行 (ui) 测试。
直到 Xcode12/iOS14 GM 构建。在 iOS13(或更低版本)中,我们在模拟器上运行它不会有任何问题。
但是在 iOS14 模拟器 iPhone11 上运行它的 Xcode12 中,我们会得到以下结果:
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 标签,但这就是我所做的:#if canImport(CoreNFC)
附近import CoreNFC
它是底层的 NFC 代码。 -weak_framework "CoreNFC"
到其他链接器标志build设置 显然,通过注释掉代码部分和删除框架链接来删除对 CoreNFC 框架的任何引用,会使崩溃消失。但这不是一个合适的选择。
在 iOS13 模拟器“设备”上从 Xcode12 运行它可以完美运行。所以我似乎无法弄清楚是什么导致了这种行为
最佳答案
Apple obviously forgot to add libnfshared.dylib for whatever reason in the final version of Xcode 12 for iOS 14 simulators. A working workaround until Apple fixes this is to copy the missing lib from Xcode 12 beta 6 over (download the beta from Apple's developer download section). The missing lib can be found here and must go into the same directory for final Xcode 12
这对我有用。 💯
如果您想避免为单个文件下载 11.25GB Xcode 12.2 beta 的麻烦。我有文件要分享。
您可以执行以下命令下载并将其放入 Xcode 包中:
sudo curl https://storage.googleapis.com/mobile-simulator-build/libnfshared.dylib -o /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Library/Developer/CoreSimulator/Profiles/Runtimes/iOS.simruntime/Contents/Resources/RuntimeRoot/usr/lib/libnfshared.dylib
希望能帮到你😉
关于ios - Xcode12 CoreNFC 模拟器库未加载,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63915728/