I'm developing a standalone xcframework (SDK) for a client's SwiftUI app. The SDK uses UIKit with storyboards for its UI components.
The client requests that we avoid accessing the rootViewController from UIWindow and controlling how our screens appear in their app. He wants us to separate those screens and return them for usage in UIHostingController to integrate UIKit views within his SwiftUI screens.
My question is about the potential downsides of using the following code for presentation:
UIApplication.shared.connectedScenes
.flatMap { ($0 as? UIWindowScene)?.windows ?? [] }
.first { $0.isKeyWindow }.rootViewController?.present(myViewController, animated: true)
Is this approach considered harmful/legacy code or prone to unexpected behavior?