Isn't it possible to use the same widgetkit extension for both iOS and WatchOS?
In the WWDC's BackyarBirds project from Apple, I can see the widget extension is added to both the multiplatform (including iOS) and the watch targets. I can also see that the SwiftUI code even uses macros to check which platform the code is running on.
However, I'm having several issues with adding the same extension to both targets. When I add it to the watch target, I get a build error that I'm trying to embed an application that also builds for iOS and that is not allowed for the watch app.
Not sure if any code here is helpful, but this is my widget UI code:
struct AkvaWidget: Widget {
private let kind = "Akva Widget"
var families: [WidgetFamily] {
#if os(iOS)
return [.accessoryCircular, .accessoryRectangular, .systemSmall]
#elseif os(watchOS)
return [.accessoryCircular, .accessoryRectangular, .accessoryInline, .accessoryCorner]
#endif
}
var body: some WidgetConfiguration {
StaticConfiguration(
kind: kind,
provider: AkvaSnapshotTimelineProvider()
) { entry in
AkvaWidgetView(entry: entry)
}
.configurationDisplayName("Akva")
.description("Keep track of your water intake.")
.supportedFamilies(families)
}
}