Our app uses CoreNFC to scan NFC tags or you can use QR if NFC is not supported. This worked pretty well and we were able to run the app in the simulator for (ui) testing purposes.
Until Xcode12 / iOS14 GM builds. In iOS13 (or lower) we wouldn't have any issues running it on a simulator.
But in Xcode12 running it on a iOS14 simulator iPhone11 we would get the following:
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
That the simulator crashes makes sense to me, since the simulator can't scan NFC tags, but this is what I've done:
#if canImport(CoreNFC)
around import CoreNFC
and it's underlying NFC code.-weak_framework "CoreNFC"
to the Other Linker Flags build settingObviously removing any references to the CoreNFC framework by either commenting out code sections and removing the framework link, makes the crash disappear. But that's not a suitable option.
Running it from Xcode12 on an iOS13 simulator 'device' works perfectly. So I can't seem to figure out what is causing this behavior
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
This works for me. 💯
If you want to avoid the hassle of downloading 11.25GB Xcode 12.2 beta for a single file. I have the file to share.
You may execute the following command to download and place it inside the Xcode package:
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
Hope it helps 😉
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:
Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Library/Developer/CoreSimulator/Profiles/Runtimes/iOS.simruntime/Contents/Resources/RuntimeRoot/usr/lib
A bit in later, but maybe useful for others...
scenario:
Some "good to use" technics:
#if canImport(CoreNFC)
import CoreNFC
...
instead of old:
@available(iOS 11.0, *) .. and similar..
Notes:
"canImport" works at compile time, so if You want to solve:
"dyld: Library not loaded: /System/Library/Frameworks/CoreNFC.framework/CoreNFC Referenced from: /var/... Reason: image not found" message
we have to pay attention to LINK section.
Link section:
-weak_framework CoreNFC
on 2 lines
(in text will be: OTHER_LDFLAGS = -weak_framework CoreNFC -lstdc++ )
Linker says that the file libnfshared (mach-o) doesn't include the binary for a simulator, which is strange because it's Apple core framework.
Create a new project with Xcode 12 and import the NFC framework. Build it and run it on a simulator. If it doesn't crash then compare the build settings specially for DYLD between those projects.
If this doesn't help, delete all the simulators and recreate new ones.
Updated:
It's bug in IOS 14 and someone has submitted a radar: openradar.appspot.com/FB8699389
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With