NEW: My new book Pro SwiftUI is out now – level up your SwiftUI skills today! >>

'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))
        window.makeKeyAndVisible()
    }
}

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.

1      

Hacking with Swift is sponsored by RevenueCat

SPONSORED In-app subscriptions are a pain to implement, hard to test, and full of edge cases. RevenueCat makes it straightforward and reliable so you can get back to building your app. Oh, and it's free if your app makes less than $10k/mo.

Learn more

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

Archived topic

This topic has been closed due to inactivity, so you can't reply. Please create a new topic if you need to.

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.