美文网首页
iOS 13 Xcode11变化 项目迁移准备

iOS 13 Xcode11变化 项目迁移准备

作者: iOS虞 | 来源:发表于2019-10-15 22:09 被阅读0次

    1.创建根视图控制器

    Xcode11之前
    func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
          self.window = UIWindow(frame: UIScreen.main.bounds)
          let rootvc = RootViewController()
          self.window.rootViewController = rootvc
          self.window.makeKeyAndVisible()
          return true
    }
    
    
    Xcode11
    QQ20191015-211731.png
    报错了Use of unresolved identifier 'window',查看代码发现Xcode11AppDelegate.swift 中删除了var window: UIWindow?之后都由SceneDelegate处理了,所以不能在AppDelegatefunc application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool创建根视图控制器了
    func scene(_ scene: UIScene, willConnectTo session: UISceneSession, options connectionOptions: UIScene.ConnectionOptions) {
            guard let windowscene = (scene as? UIWindowScene) else { return }
            window = UIWindow(windowScene: windowscene)
            window?.frame = UIScreen.main.bounds
            let rootvc = RootViewController()
            let nav = UINavigationController(rootViewController: rootvc)
            window?.rootViewController = nav
            window?.makeKeyAndVisible()
        }
    

    2.获取UIWindow

    Xcode11之前
    let window = UIApplication.shared.keyWindow
    
    Xcode11
    UIApplication.shared.windows.first
    

    for scene in UIApplication.shared.connectedScenes {
         let windowscene: UIWindowScene = scene as! UIWindowScene
         if windowscene.activationState == .foregroundInactive {
             let window = windowscene.windows.first!
             break
         }
     }
    

    let window = (UIApplication.shared.connectedScenes.first?.delegate as? SceneDelegate)?.window
    

    相关文章

      网友评论

          本文标题:iOS 13 Xcode11变化 项目迁移准备

          本文链接:https://www.haomeiwen.com/subject/tvdemctx.html