How to Set up a SwiftUI App for iOS 14 but still default to AppDelegate if iOS 13?

Viewed 948

I'd like to port my existing UIKit App to use the new App API for iOS 14. (but still utilize the AppDelegate methods via UIApplicationDelegateAdaptor, however I would still like to support iOS 13. Is there a way I can set up so that if iOS 14, use the App as @main but if iOS 13 use AppDelegate as @UIApplicationMain? Even the below code won't compile as my minimum build target is iOS 13:

@available(iOS 14.0, *)
@main
struct HockeyTrackerApp: App {

    // inject into SwiftUI life-cycle via adaptor !!!
    @UIApplicationDelegateAdaptor(AppDelegate.self) var appDelegate

    var body: some Scene {
        WindowGroup {
            HomeView()
        }
    }
}
0 Answers
Related