Issue with UIKit windows on Xcode 11 and iOS 13 beta 2

When presenting content on a new window, it automatically dismisses itself.


I'm presenting a ViewController in a new window with something like the following extension:

extension UIViewController {

     func present() {
          let window = UIWindow(frame: UIScreen,main.bounds)
          let viewController = UIViewController()
          viewController.view.background = .clear
          window.rootViewController = viewController
          window.windowLevel = UIWindow.level.alert + 1
          window.makeKeyAndVisible()
          viewController.present(self, animated: true, completion: nil)
     }
}


I can see the following coming up in the debugger.

0000-00-00 00:00:00.000000+0000 App[0000] [TraitCollection] Class _UIFormSheetPresentationController overrides the -traitCollection getter, which is not supported. If you're trying to override traits, you must use the appropriate API.
0000-00-00 00:00:00.000000+0000 App[0000] [TraitCollection] Class _UIPageSheetPresentationController overrides the -traitCollection getter, which is not supported. If you're trying to override traits, you must use the appropriate API.

Anyone seen anything similar? Are the new scenes acting up here? I'm quite certain this behaviour did not occur on iOS 13 beta 1

Replies

I have the same issue, it's crashing the app , looking for a solution...

You might be able to get around this by setting `self.modalPresentationStyle = .fullscreen`, which won't use the new modal presentation style, but will also not use the `_UIPageSheetPresentationController` class, which seems to be causing the issue.

I've tried setting the `self.modalPresentationStyle = .fullscreen` before, but the issue comes when trying to use a new window which is the objective here. Still an issue on iOS 13 Beta 3.

Facing the exact same issue. @carrharr Did you have any luck getting this resolved?

It works if you hold a reference to the UIWindow e.g.


var window: UIWindow?

extension UIViewController {
    func present() {  
        window = UIWindow(frame: UIScreen,main.bounds)
    }
}


I don't know why this is needed...

I had the same issue when working with a framework .

my solution was to wrap my view controller in a navigation controller and instead present that navigation controller modally you can hide the navigation bar if needed


like this

func present() {

let viewController = UIViewController()

let navigationController = UINavigationController(rootViewController: viewController)
navigationController.navigationBar.barStyle = .blackTranslucent

// Present it modally from the current controller

present(navigationController, animated: true, completion: nil)


}