我在 iPadOS 14 上使用新的GCMouse.mice() API。
我的蓝牙鼠标(Logitech MX Master 2S)被清晰识别,我可以用它导航操作系统甚至我的应用程序。如果我去Settings → Accessibility → AssistiveTouch → Devices,我的鼠标就在那里。
但是,无论我在什么时候调用GCMouse.mice()
,结果都是一个空列表,并且GCMouse.current
始终为零。
同样,我会听,GCMouseDidConnect
但它永远不会触发。
重现:我将此代码添加到AppDelegate.swift
默认项目模板中。
import UIKit
import GameController // new
@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {
// new:
@objc func showMice() { print(GCMouse.mice()) }
@objc func newMouse(notification: Notification) { print(notification) }
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
// Override point for customization after application launch.
// new:
Timer.scheduledTimer(timeInterval: 1, target: self, selector: #selector(showMice), userInfo: nil, repeats: true)
NotificationCenter.default.addObserver(self, selector: #selector(newMouse), name: NSNotification.Name.GCMouseDidConnect, object: nil)
return true
}
...
在控制台中,我只看到:
2020-09-21 21:52:52.737457+0200 MouseTest[1639:1517093] Metal API Validation Enabled
[]
[]
[]
[]
[]
...
有什么我想念的吗?可能有我不知道的权利吗?