For a few reasons, we as a team decided to transition away from the SwiftUI.App
launch cycle. We need more control and customisation, and managing the scenes directly ourselves was the best way forward.
We're now trying to run the app entirely from our own App and Scene delegates, however we've run into a problem: When we update the app on a device from a version that uses SwiftUI.App
to a version that uses App and Scene delegates, the first initial launch fails with a black screen.
The reason for this is that FrontBoardServices
attempts to use the existing UISceneSession
after the update, with the SwiftUI.AppSceneDelegate
class, instead of calling application(configurationForConnecting:options:
). Since SwiftUI.AppSceneDelegate
still exists in the scope, the internal property _configurationNeedsReevaluation
on UISceneSession returns false and the app attempts to launch from SwiftUI.AppSceneDelegate
.
As far as I can tell, there doesn't seem to be a way to fix this that doesn't involve invoking the private method -[UISceneSession _updateConfiguration:]
to force the configuration to use the correct Scene delegate.
if let sceneSession = application.openSessions.first(
where: { $0.configuration.delegateClass.map(NSStringFromClass) == "SwiftUI.AppSceneDelegate" }
) {
let newConfig = UISceneConfiguration(name: nil, sessionRole: .windowApplication)
newConfig.delegateClass = SceneDelegate.self
sceneSession.perform(Selector(("_updateConfiguration:")), with: newConfig)
}
Could you maybe advise on a way forwards?