tvos 15 - Siri Remote 未在数组中返回:GCController.controllers()

tvos 15 - Siri Remote not returning in the array: GCController.controllers()

swiftUI & tvOS 15 中,当调用 GCController.controllers() 获取连接到苹果电视,

import GameController

 ...

let siriRemoteAsGameController = GCController.controllers().first

Siri Remote 没有注册为第一个控制器,事实上它根本没有注册!

直到 tvOS 15(例如 14.7)它都在工作

即使我注册了通知,也不会为已连接的 Siri 遥控器调度连接事件

NotificationCenter.default.addObserver(forName: .GCControllerDidConnect, object: nil, queue: .main) { note in
        print("GCControllerDidConnect")
        if let detectedGCController = note.object as? GCController {
            print("Controller Detected")
        }
    }

GCController.startWirelessControllerDiscovery(completionHandler: {})

根据 Appel's $#itty documentation

,我找不到那个区域的变化

任何帮助将不胜感激

基于 this answer 似乎需要在 调用(至少一次)到 GCController.controllers() 之后与远程 进行交互,因此解决方案是这样的:

import GameController

struct ContentView2: View {
  var body: some View {
    // first call before remote interaction
    let a = print("controllers: \(GCController.controllers())")
    
    Button("Query controllers") {
      // second call after a press button via remote interaction occurred
      print("controllers: \(GCController.controllers())")
    }
  }
}