0

I tried this:

let window = UIApplication.shared.windows.first

print("safeareatop: \(window?.safeAreaInsets.top)")

and get:

'windows' was deprecated in iOS 15.0: Use UIWindowScene.windows on a relevant window scene instead

so I tried:

UIWindowScene.windows.first

but I get another error, the error messages from xcode are absolutely useless compared to android studios btw

the "solutions" from here:

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?

and here:

'windows' was deprecated in iOS 15.0

are still giving me this message.

So how to do this?

user19591083
  • 151
  • 1
  • 10

2 Answers2

2

With access to window provided in reference (https://stackoverflow.com/a/60359809/12299030) works fine here.

Tested with Xcode 13.4 / iOS 15.5 / iPhone 12

demo

Asperi
  • 228,894
  • 20
  • 464
  • 690
0

Use GeometryReader

struct ContentView: View {
    var body: some View {
        GeometryReader { proxy in
            Text("Something")
                .onAppear {
                    print(proxy.safeAreaInsets)
                }
        }
    }
}
narek.sv
  • 845
  • 5
  • 22