How to get rid of message 'windows' was deprecated in iOS 15.0: Use UIWindowScene.windows on a relevant window scene instead with AdMob banner?
You can use following as UIApplication.shared.currentUIWindow()?.rootViewController
public extension UIApplication {
func currentUIWindow() -> UIWindow? {
let connectedScenes = UIApplication.shared.connectedScenes
.filter { $0.activationState == .foregroundActive }
.compactMap { $0 as? UIWindowScene }
let window = connectedScenes.first?
.windows
.first { $0.isKeyWindow }
return window
}
}
Why it is throw an error as 'windows' was deprecated in iOS 15.0: Use UIWindowScene.windows on a relevant window scene instead in SwiftUI?
Well, the warning message reflects the essence of the problem pretty fully.
Apple really deprecated UIApplication.shared.windows
, so to fix your warning, instead of UIApplication.shared.windows.first?
you should use:
UIApplication
.shared
.connectedScenes
.flatMap { ($0 as? UIWindowScene)?.windows ?? [] }
.first { $0.isKeyWindow }
Then, your .padding
view modifier will look like this:
.padding(.top, UIApplication
.shared
.connectedScenes
.flatMap { ($0 as? UIWindowScene)?.windows ?? [] }
.first { $0.isKeyWindow }?.safeAreaInsets.top)
windows' was deprecated in iOS 15.0
this has been updated for iOS 15
UIApplication
.shared
.connectedScenes
.compactMap { $0 as? UIWindowScene }
.flatMap { $0.windows }
.first { $0.isKeyWindow }
.rootViewController?.present()
Related Topics
Swiftui Set Position to Center of Different View
Ios8 Custom Keyboard - Copy & Paste to Uipasteboard
Why Can't We Use Protocol 'Encodable' as a Type in the Func
Sprite Kit Physicsbody.Resting Behavior
How to Rewrite Swift ++ Operator in : Ternary Operator
Implicit Return in a Closure Causing an Error
Nstextfield, Change Text in Swift
How to Open a Nspopover at a Distance from the System Bar
Moving Node on Top of a Moving Platform
Turn Off Xcode's Unused Variable Warnings While Typing
Grab Frames from Video Using Swift
When and How to Use @Noreturn Attribute in Swift
Adding Local Dependencies in Xcode11 Using Spm
Parse.Com Querying User Class (Swift)
Format Realtime Stopwatch Timer to the Hundredth Using Swift
Ambiguous Use of Subscript (Swift 3)