The documentation for how to handle focus & triggering the GKAccessPoint seems to be outdated for tvOS:
https://developer.apple.com/documentation/gamekit/adding_an_access_point_to_your_game
For tvOS specifically, the documentation has examples that refer to GKAccessPoint.focusFeedback
and GKAccessPoint.shared.triggerAccessPoint which
don't exist.
I can use shared.isFocused()
instead of .focusFeedback(),
and .trigger {}
instead of .triggerAccessPoint {},
but then it seems I can either set the focus to the accessPoint or I can trigger it, but I can't do both.
For example, the following code captures the focus via a button, and then redirects the focus to the GKAccessPoint. You can still press the tvOS remote to visually show the button pressing, but it never prints out anything or triggers the access point.
If you remove the .focusable(true) {...}
section at the end, then the button will trigger the accessPoint, but it won't show it as focused.
I seem to be missing something! Any ideas?
#if os(tvOS)
// this is used to "capture" focus invisibly, so it can be handed off to Game Center's GKAccessPoint
VStack(alignment: .leading, content: {
Button("") {
print("Button representing GKAccessPoint was pressed!")
GKAccessPoint.shared.trigger {
print("\nI WAS TRIGGERED!!! by a button\n")
}
}
.focusable(true) { isFocused in
if isFocused {
print("focused!")
GKAccessPoint.shared.isFocused = true
} else {
GKAccessPoint.shared.isFocused = false
print("NOT focused!")
}
}
.opacity(0.1)
})
.focusSection()
#endif