Error running app with widgetKit on iOS 13

My app has a widgetKit extension, and works perfectly on iOS 14. When I run the app on an iOS 13 device I get this error:

dyld: Library not loaded: /System/Library/Frameworks/WidgetKit.framework/WidgetKit
  Referenced from: /private/var/containers/Bundle/Application

I think it means I’m calling widgetKit but it doesn’t know what it is. How can I avoid this error or fix it?

Replies

Hi iEvanC, WidgetKit is not supported on iOS 13, it is only available in iOS 14.
To get around this, make sure WidgetKit is included in the “embed frameworks” build phase, and set it to “Optional”.

It will then work in iOS 13 and 14.
  • Select your target

  • Build Phases

  • Link binary with libraries

  • Add WidgetKit and set its Status to "Optional"

Make sure your app is checking to see if its running on iOS 13 or iOS 14:

Something such as:

Code Block struct BackCol: View {
  @available(iOS 13.0.0, *)
  var body: some View {
  


Are u calling WidgetCenter.shared.reloadAllTimelines()?
I'm having the exact same issue.

I have tree building targets:
Main app: iOS 13
TodaysExtension: iOS 13
WidgetKit: iOS 14

I assumed that the Deployment info section was a way to specify in witch iOS versión should the target be available.

Is there a way to exclude completely the target for non iOS 14 versions?


I fixed it by this:
  1. edit your code in iOS app target

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

2. “embed frameworks” build phase, and set it to “Optional”.