iosswiftxcode12today-extensionwidgetkit

Is it possible to run WidgetKit code in iOS 13?


I'm creating a project that has a requirement of having a Widget. My project is created using Xcode 12.4, the minimum iOS version supported by my iOS App is iOS 13, hence my App's target deployment iOS version is iOS 13. Since WidgetKit is available only in iOS 14, I created a new target for my Widget with a deployment target of iOS 14.

Could it be possible to make the deployment iOS version of my Widget to iOS 13 so that I can run it in iOS 13 iPhones? Actually I tried it but I'm getting an error "'main()' is only available in application extensions for iOS 14.0 or newer". I tried adding @available annotation above @main but it is not working. See photo below.

enter image description here

I want to make this work because Today's Widget is no longer available in Xcode 12. We still want to show some widgets when our user is running in iOS 13, like the Calendar and Weather Apps widgets.


Solution

  • WidgetKit

    The WidgetKit framework is only supported in iOS 14+, so no you cannot change the deployment version of your widget to iOS 13 because this is below the minimum iOS version. To learn more about WidgetKit refer to Apple's documentation here.

    Notification Center

    This is the depreciated api for creating Today View widgets in iOS versions earlier than iOS 14. If you want a widget that can be used in the Today View menu on devices running iOS 13 or earlier, then you need to use the Notification Center framework. However, this framework does not work the same as WidgetKit. You will need to create entirely different widgets for them to work with Notification Center. To learn more about Notification Center refer to Apple's documentation here.

    Overall, it is my recommendation that if you are trying to create a widget for your app it is not worth the effort in creating widgets that support iOS 13 and earlier. For one, these widgets are only available in the today view not on the main home screen. Also, very few users still run iOS 13 compared to iOS 14, so it simply would not be worth supporting the small additional user base.