How to add a SceneDelegate to SwiftUI app with SwiftUI App Lifecycle XCode 12

Viewed 2429

I created an application in SwiftUI with SwiftUI app lifecycle. Is there a way to add SceneDelegate class to the main construct. Adding an AppDelegate seems possible

import SwiftUI

@main
struct SampleApp: App {
    
    @UIApplicationDelegateAdaptor(AppDelegate.self) var appDelegate
    
    var body: some Scene {
        WindowGroup {
                HomeView()
                // .colorScheme(.light)
        }
    }
}

// App Delegate class for conventional lifecycle capturing
final class AppDelegate: NSObject, UIApplicationDelegate {
    
    func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey : Any]? = nil) -> Bool {
        
        NetworkManager.shared.startMonitoring()
        return true
    }
    
    func applicationWillTerminate(_ application: UIApplication) {
        NetworkManager.shared.stopMonitoring()
    }
}
0 Answers
Related