我正在开发一个应用程序,其中包括Gamecontroller。我试图显示连接控制器计数,但它不起作用。
以下是我的简单代码:
import Cocoa
import GameController
@NSApplicationMain
class AppDelegate: NSObject, NSApplicationDelegate {
func applicationDidFinishLaunching(_ aNotification: Notification) {
// Insert code here to initialize your application
// - MARK: Controllers
let controllers = GCController.controllers()
print(controllers.count)
}
func applicationWillTerminate(_ aNotification: Notification) {
// Insert code here to tear down your application
}
}

它总是打印0
我做错了什么?
编辑:
问题是我没能补充一下:
let ctr = NotificationCenter.default
ctr.removeObserver(self, name: .GCControllerDidConnect, object: nil)
ctr.removeObserver(self, name: .GCControllerDidDisconnect, object: nil)在连接控制器时处理
发布于 2022-02-07 11:44:56
修正了使用本教程:tvOS游戏,第1部分:使用游戏控制器框架
下一个问题是找到设备的唯一标识符.
编辑:
问题是我没能补充一下:
let ctr = NotificationCenter.default
ctr.removeObserver(self, name: .GCControllerDidConnect, object: nil)
ctr.removeObserver(self, name: .GCControllerDidDisconnect, object: nil)在连接控制器时处理
https://stackoverflow.com/questions/71015077
复制相似问题