App Navigation stuck while Air Play is enabled

My app needs to display through the iMac and Apple TV for the demonstration purpose

But during the AirPlay the app navigation is stuck because of the root view controller is getting as nil

I am using the below code to get the root view controller

let scenes = UIApplication.shared.connectedScenes let windowScene = scenes.first as? UIWindowScene let window = windowScene?.windows.first

return window?.rootViewController

Since rootViewController is nil, I can't push a new VC or pop to a specific VC in the navigation stack

Only when the Air Play is turned off, I can continue the navigation in the app

So this really becoming a blocker issue. Please provide your comments

I am running on iOS 16.1.1 in the iPhone and My Xcode version is 14.3

I found a similar issue related to navigation here https://developer.apple.com/forums/thread/695932 .

So I just followed as mentioned in the above answer. I created a static member for window property in SceneDelegate and initialising it on the scene willConnectTo method of the SceneDelegate.

And I am using this static member in other parts of the application to get fetch the rootViewController . This solves my issue. I can now use the app navigation with out any issues while the Air Play is active

App Navigation stuck while Air Play is enabled
 
 
Q