You probably have a WidgetBundle
type in your widget extension like this:
@main
struct MyWidgets: WidgetBundle {
var body: some Widget {
SmallWidget()
MediumWidget()
LargeWidget()
}
}
Instead of defining one WidgetBundle
annotated @main
, define two WidgetBundle
s (one with the extra-large widget, the other without), and do not annotate either one @main
.
Define your own non-WidgetBundle
type with a static func main
and annotate your type @main
.
In your static func main
, call the main
of the appropriate WidgetBundle
type depending on whether you're on iOS 15.
struct MyWidgets_14: WidgetBundle {
var body: some Widget {
SmallWidget()
MediumWidget()
LargeWidget()
}
}
@available(iOS 15, *)
struct MyWidgets_15: WidgetBundle {
var body: some Widget {
SmallWidget()
MediumWidget()
LargeWidget()
ExtraLargeWidget()
}
}
@main
struct WidgetExtMain {
static func main() {
if #available(iOS 15, *) {
MyWidgets_15.main()
} else {
MyWidgets_14.main()
}
}
}