iOS 13 Xcode11变化 项目迁移准备

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
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

友情链接更多精彩内容