LoginSignup
0
0

More than 1 year has passed since last update.

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

Last updated at Posted at 2022-05-13

警告文を消したい

'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(where: { $0.activationState == .foregroundActive }) as? UIWindowScene
windowScene?.windows.first?.rootViewController?.present(view, animated: true, completion: nil)

おわり

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

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0