警告文を消したい
'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以前
UIApplication.shared.keyWindow?.rootViewController?.present(view, animated: true, completion: nil)
iOS13以降
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)
おわり
サンプルプロジェクトを置いときます