Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

debugging

tvos

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?

like image 940
Wayne Hartman Avatar asked Sep 28 '15 16:09

Wayne Hartman


2 Answers

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

like image 59
Justin Voss Avatar answered Nov 04 '22 19:11

Justin Voss


Since tvOS 11, troubleshooting unreachable items got a lot easier, just add this to the viewDidLoad of the ViewController in Question:

 if #available(tvOS 11.0, *) {
  NotificationCenter.default.addObserver(
    forName: NSNotification.Name.UIFocusMovementDidFail
  ) { [weak self] notification in
    let context = notification.userInfo![UIFocusUpdateContextKey] as! UIFocusUpdateContext
    print(context) // If you add a breakpoint here you can quicklook the context in the debugger for more information
    print(UIFocusDebugger.checkFocusability(for: self!.collectionView)) // replace collectionView with the view you want to check
  }
}

This results in debug output like:

<UIFocusUpdateContext: 0x6080000fe800: previouslyFocusedItem=<UIKeyboard 0x7fc597d75610>, nextFocusedItem=(null), focusHeading=Down>

The following issues were found that would prevent this item from being focusable:
- ISSUE: The item is being visually occluded by the following items:
<UIView 0x7fc597c3a9e0>
like image 40
Lutzifer Avatar answered Nov 04 '22 18:11

Lutzifer