search
LoginSignup
0
Help us understand the problem. What are the problem?

posted at

updated at

【Swift】Windowの仕様変更が激しい

警告文を消したい

'keyWindow' was deprecated in iOS 13.0: Should not be used for applications that support multiple scenes as it returns a key window across all connected scenes
'windows' was deprecated in iOS 15.0: Use UIWindowScene.windows on a relevant window scene instead

iOS13以前

スクリーンショット 2022-05-13 14.37.29.png

UIApplication.shared.keyWindow?.rootViewController?.present(view, animated: true, completion: nil)

iOS13以降

スクリーンショット 2022-05-13 14.37.59.png

UIApplication.shared.windows.first?.rootViewController?.present(view, animated: true, completion: nil)

iOS15以降

let WindowScene = UIApplication.shared.connectedScenes.first as? UIWindowScene
WindowScene?.windows.first?.rootViewController?.present(view, animated: true, completion: nil)

おわり

サンプルプロジェクトを置いときます

Register as a new user and use Qiita more conveniently

  1. You can follow users and tags
  2. you can stock useful information
  3. You can make editorial suggestions for articles
What you can do with signing up
0
Help us understand the problem. What are the problem?