WidgetCenter causing app to crash went built to iOS 13.X

I have this block of code in my project and whenever I build to a < iOS 14.0 it crashes causing the error below
Code Block
if #available(iOS 14.0, *) {
if shouldAlertWidgetCenter {
WidgetCenter.shared.reloadAllTimelines()
}
}

If I comment out the one line
Code Block
WidgetCenter.shared.reloadAllTimelines()

Then it runs fine even though it is in the #available check and shouldn't make any difference.

I tried putting the import inside of the canImport block and still crashes unless that line is commented out

Code Block
#if canImport(WidgetKit)
import WidgetKit
#endif


I'm drawing a blank at what I'm doing wrong. Thanks a lot if anyone has any ideas

Crash Log:
Code Block
dyld: Library not loaded: /System/Library/Frameworks/WidgetKit.framework/WidgetKit
Referenced from: /private/var/containers/Bundle/Application/60E4FB21-B28D-4E44-8972-0370BEB6DAE8/_.app/__
Reason: image not found
dyld: launch, loading dependent libraries
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
(lldb) 

Answered by Jasonloewy in 622695022
If anyone find this with the same problem, the solution is adding WidgetKit to the Build Phase -> Link Libraries and make it optional
Accepted Answer
If anyone find this with the same problem, the solution is adding WidgetKit to the Build Phase -> Link Libraries and make it optional
@Jasonloewy This info helped me a great deal. Thank you.
WidgetCenter causing app to crash went built to iOS 13.X
 
 
Q