Now, thanks to Apple extending iOS to support multiple instantiations of a running App, that method is deprecated and I can no longer figure out how to get a reference to current-scene/current-window.
Generally, the code in question that needs a window or scene should either be passed in a reference to to those objects, or obtain them through something like this: view.window.windowScene
.
Did you see this one (at the end of the thread) ?
Please don't do anything like this "solution". For starters, isKeyWindow
will return YES if a particular window is key in its scene as of iOS 15 (and related release on other platforms). isKeyWindow
is "scene-level" and not "application-level" now.
Main question, Apple - Why does getting something so simple have to be so freaking hard now? When is enough enough in expanding the capabilities of iOS? And who the heck is gong to run multiple instantiations of the same app on an iPad???
The "solutions" above were never very good. And since iPadOS 13, it was never safe to access the application-level key window because it could be pointing to a completely different scene.
As mentioned above, in most cases, code that needs access to a scene or a window should be given one or can find one via context (e.g a view it owns).
Since multiple system processes can be involved in providing scenes to the app (for example on CarPlay) application-level concepts like UIApplication.shared.keywindow
are not only not useful, they are harmful.
that method is deprecated and I can no longer figure out how to get a reference to current-scene/current-window.
Instead of searching for a solution, it would be better to start here. Why does the code in question not have a reference to a scene? Why does it need to reach up to something like UIApplication.shared
for this information?