WWDC22 SALE: Save 50% on all my Swift books and bundles! >>

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

Forums > Swift

I've been using this code on an app for a while to make sure that whenever it is opened, it always defaults back to the login page, no matter what. But with the advent of iOS 15.0 i've started gettting the warning:

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

.onReceive(NotificationCenter.default.publisher(for: UIApplication.didEnterBackgroundNotification)) { _ in
    if let window = UIApplication.shared.windows.first {
        window.rootViewController = UIHostingController(rootView: AuthenticateView(settings: settings, theCollection: theCollection))

is there a better way to make an app always open on a login page, no matter what? I don't understand enough about what it's doing to make the warning go away. The scheme is that anytime the app passes into the background, it goes to the login page before anyone can get back into it. I have the exact code above sprinkled thru my app on every view, so no matter which view is active, if the app goes into the background it'll default back to the login page. I think I got the original code from Stack Overflow.


Hacking with Swift is sponsored by Emerge

SPONSORED Why are Swift reference types bad for app startup time, and what’s the performance cost of protocol conformances? That’s just a couple of the topics you can learn about on the Emerge blog — written by the app performance experts behind Emerge’s advanced app optimization and monitoring tools, based on their experience of working at companies like Apple, Airbnb, Snap, and Spotify.

Find out more

Sponsor Hacking with Swift and reach the world's largest Swift community!

Reply to this topic…

You need to create an account or log in to reply.

All interactions here are governed by our code of conduct.

Unknown user

You are not logged in

Log in or create account

Link copied to your pasteboard.