Search code examples
debuggingtvos

Are there any hidden tools in tvOS for Focus Engine debugging?


One of my favorite hidden debugging tools for iOS is using recursiveDescription on UIView instances. This is very useful for troubleshooting view locations that may be off-screen, for example. Debugging the Focus Engine on tvOS brings its own set of challenges, especially around what it thinks are focusable elements.

Are there any hidden debugging tools for tvOS to introspect what is going on inside the Focus Engine?


Solution

  • There are two helpful methods, both of which are actually documented in the App Programming Guide for tvOS.

    UIView

    If you're trying to move focus to a particular view and can't, there's a debugging method on UIView that can help explain why: _whyIsThisViewNotFocusable

    The output from this method looks something like this:

    (lldb) po [(UIView *)0x148db5234 _whyIsThisViewNotFocusable]
    ISSUE: This view has userInteractionEnabled set to NO. Views must allow user interaction to be focusable.
    ISSUE: This view returns NO from -canBecomeFocused.
    

    UIFocusUpdateContext

    The UIFocusUpdateContext object supports Xcode's QuickLook feature, so if you're paused in the debugger you can press spacebar (or click the eyeball icon next to the variable) to see a graphical representation of what the focus engine sees (image is from Apple's documentation):

    QuickLook example of focus update context