Created
September 18, 2024 19:23
-
-
Save christianselig/bb3eec39f232c72a568309be7591568f to your computer and use it in GitHub Desktop.
Proper way to handle backwards compatibility of iOS widgets
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import WidgetKit | |
import SwiftUI | |
@main | |
struct WidgetExtMain { | |
static func main() { | |
if #available(iOS 18.0, *) { | |
MyWidgets_18.main() | |
} else { | |
MyWidgets_17.main() | |
} | |
} | |
} | |
@available(iOS 17.0, *) | |
struct MyWidgets_17: WidgetBundle { | |
var body: some Widget { | |
TriviaPalWidget() | |
PixelPalsLiveActivity() | |
} | |
} | |
@available(iOS 18.0, *) | |
struct MyWidgets_18: WidgetBundle { | |
var body: some Widget { | |
TriviaPalWidget() | |
HeartControlWidget() | |
PixelPalsLiveActivity() | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment