App crashed on iOS 13, after switching rootviewcontroller

139 Views Asked by At

Application runs fine on iOS 12. But crashed on iOS 13.1. I think the issue is in the setting root view controller.

let storyboard = UIStoryboard(name: storyBoard, bundle: nil)
let desiredViewController = storyboard.instantiateViewController(withIdentifier: identifier);
self.window?.switchRootViewController(desiredViewController,animated: animate,options:options)

and the extension is:

extension UIWindow {

func switchRootViewController(_ viewController: UIViewController,  animated: Bool = true, duration: TimeInterval = 0.3, options: UIView.AnimationOptions = .transitionFlipFromRight, completion: (() -> Void)? = nil) {
    guard animated else {
      rootViewController = viewController
      return
    }

    UIView.transition(with: self, duration: duration, options: options, animations: {
      let oldState = UIView.areAnimationsEnabled
      UIView.setAnimationsEnabled(false)
      self.rootViewController = viewController
      UIView.setAnimationsEnabled(oldState)
    }) { _ in
      completion?()
    }
  }
}
0

There are 0 best solutions below