nstack-io / nstack-ios-sdk

MIT License
5 stars 10 forks source link

Alerts are not presented when using the SwiftUI `App` protocol. #106

Closed andrewlloyd100 closed 1 year ago

andrewlloyd100 commented 1 year ago

When starting the app using the SwiftUI App protocol, alerts presented from NStack are not displayed in app. If you initialise your app with a UIHostingController in a UIWindow, it works as expected.

Eg;

@main
struct DemoApp: App {
    @UIApplicationDelegateAdaptor(AppDelegate.self) var appDelegate

    // MARK: Scenes
    var body: some Scene {
        WindowGroup {
            AppCoordinatorView(coordinator: appDelegate.coordinator)
        }
    }
}

Does not work

@main
class AppDelegate: UIResponder, UIApplicationDelegate {

    var coordinator = AppCoordinator()
    let window = UIWindow(frame: UIScreen.main.bounds)

    func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {

        coordinator.start(options: launchOptions)

        let appView = AppCoordinatorView(coordinator: coordinator)
        self.window.rootViewController = UIHostingController(rootView: appView)
        self.window.makeKeyAndVisible()
        return true
    }
}

Works as expected.

I suspect its something to do with using SwiftUI instead of UIKit and UIWindow specifically but not entirely sure.