5

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()
        }
    }
}
GarySabo
  • 5,806
  • 5
  • 49
  • 124
  • Does this topic answer your question https://stackoverflow.com/questions/62935053/use-main-in-xcode-12? – Asperi Nov 11 '20 at 17:21
  • @Asperi the.blaggy's solution seems to work in iOS 14, but he mentions in his answer that you also need to set up a `sceneDelegate` for iOS 13? Confused why this would be necessary given that if iOS 13 Xcode is reverting to the `AppDelegate` so why would a scene delegate be necessary? – GarySabo Nov 11 '20 at 18:51

0 Answers0