Search code examples
swifttvos

TVOS requires 2 Menu Button Presses to exit to Dashboard from Root Controller


I have been charged with updating an existing TVOS project. I have run into a bit of a snag.

If I am on the root controller(ie: the controller that presents on app launch.)

Pressing the Menu button takes me to an empty gray/white screen. A second press of menu returns me to the Dashboard.

I have tried to use the hierarchy viewer to see what exactly that gray/white screen is, but it has not helped. The gray/white screen consists of a UIWindow with a UILayoutContainerView, that contains a single UINavigationTransitionView in it. I can find no other identifiable characteristics about it to help me identify what exactly is going on.

When launched the app loads a UINavigationController that presents a UIViewController. Neither the Nav controller nor the presented ViewController override pressesBegin, pressesEnd or assign any gestureRecongnizers to intercept or otherwise override the Menu button functionality.

Near as I can tell the app should exhibit the default Menu button pressed behavior of navigate back to the root, then exit to the Dashboard once at the root. That said, the Menu button does navigate backwards as it should. It just does not terminate the app once at the root. When it does go to the gray/white screen none of the functions: applicationWill... are executed until after the second press of the Menu button on the remote. The app will also resume to this gray/white screen instead.

My question is thus, what is going on here. Baring that how can I debug this behavior more effectively.

I have tried to be thorough with this explanation. I recognize that without code things get hard. Thing is, I have no idea what code would be relevant so any guidance or requests for specific code that may be useful will be posted.

Thanks.


Solution

  • Let's call your navigation controller A and the presented view controller B.

    It sounds like what's happening is that A doesn't actually have any children, or it has a blank view controller as it's only child. I'm assuming that you never call pushViewController(_, animated:) on A? What are you passing to A when you create it with init(rootViewController:)?

    When you press the Menu button the first time, UIKit is automatically dismissing the presented view controller B, and revealing the empty navigation controller A. The gray screen you see is actually the tvOS wallpaper, which is rendered outside the app's view hierarchy.

    Then pressing the Menu button the second time actually causes the app to resign, since the navigation controller A doesn't have any more children to pop.

    So it sounds like you should either:

    • Add the view controller B as a child of A, instead of presenting it.

    • Or, set B as the root view controller and forget about A.