‘windows’ was deprecated in ios 15.0: use uiwindowscene.windows on a relevant window scene instead

In iOS 15.0, the usage of the key “windows” was deprecated. Instead, the recommended approach is to use the “uiwindowscene.windows” property on a relevant window scene. This change is aimed at providing better compatibility and improved management of multiple window scenes.

To understand this change better, let’s consider an example. Let’s assume we have an app with multiple scenes, each representing a different view or functionality within the app. In a scenario where you need to access the windows within a specific scene, you would use the “uiwindowscene.windows” property as follows:

      
         // Get the current active scene
         let activeScene = UIApplication.shared.connectedScenes
             .filter({$0.activationState == .foregroundActive})
             .first
            
         if let windowScene = activeScene as? UIWindowScene {
             // Access windows property of the relevant window scene
             let windows = windowScene.windows
             
             // Perform necessary operations with the windows
             ...
         }
      
   

Here, we first get the currently active scene using the “connectedScenes” property of the shared UIApplication instance. We filter the scenes based on their activation state to find the foreground active scene. Then, we cast it as a UIWindowScene to access the “windows” property, which gives us an array of windows associated with that scene. Finally, you can perform any necessary operations with these windows.

This updated approach ensures compatibility with changes in the iOS ecosystem and provides a more structured way of managing windows within different scenes of your app. By migrating to the usage of “uiwindowscene.windows”, you ensure the smooth functioning of your app on iOS 15.0 and later versions.

Same cateogry post

Leave a comment