Why widgets from iOS app are not available on the list on iOS 16, while on ios 17 and 15 are available?
This is how they are defined in widget bundle:
import WidgetKit
import SwiftUI
@main
struct ZeroWidgetBundle: WidgetBundle {
@WidgetBundleBuilder
var body: some Widget {
FirstWidgetBundle().body
SecondWidgetBundle().body
ThirdWidgetBundle().body
}
}
struct FirstWidgetBundle: WidgetBundle {
@WidgetBundleBuilder
var body: some Widget {
WidgetLatestNews()
WidgetLatestVideos()
WidgetDailyText()
WidgetOfficialSite()
}
}
struct SecondWidgetBundle: WidgetBundle {
@WidgetBundleBuilder
var body: some Widget {
WidgetWatchtowerStudy()
WidgetCurrentMonth()
WidgetComing()
if #available(iOS 16.1, *) {
WidgetCurrentTime()
}
}
}
struct ThirdWidgetBundle: WidgetBundle {
@WidgetBundleBuilder
var body: some Widget {
WidgetMinistry()
if #available(iOS 17.0, *) {
WidgetTimer()
}
}
}
it just works on 17 and 15, and doesn't work on 16. It started happening after 17 was released. It was working before. Where is the problem?
This is the screenshot where you can see the problem. Exactly THE SAME code was compiled on three devices using Xcode 15.0 (15A240d)
Feedback Assistant to Apple:
The solution is very simple. There is no explanation why Xcode compiles code excluded by #available
(here WidgetTimer
). But working solution for that is the following:
struct ThirdWidgetBundle: WidgetBundle {
var body: some Widget {
if #available(iOS 17.0, *) {
return WidgetBundleBuilder.buildBlock(WidgetMinistry(), WidgetTimer())
} else {
return WidgetMinistry()
}
}
}