问题描述
有没有办法检测外接(蓝牙或usb)键盘是否连接到iPad?
Is there a way to detect if an external (bluetooth or usb) keyboard is connected to the iPad?
推荐答案
间接和SDK安全的方法是使文本字段成为第一响应者。如果存在外部键盘,则不应发布 UIKeyboardWillShowNotification
本地通知。
An indirect and SDK-safe way is to make a text field a first responder. If the external keyboard is present, the UIKeyboardWillShowNotification
local notification shall not be posted.
你可以收听GSEventHardwareKeyboardAttached
( kGSEventHardwareKeyboardAvailabilityChangedNotification
)Darwin通知,但这是一个私有API,因此您的应用可能会获得如果你使用它就被拒绝了。要检查外部硬件是否存在,请使用私有 GSEventIsHardwareKeyboardAttached()
函数。
You can listen to the "GSEventHardwareKeyboardAttached"
(kGSEventHardwareKeyboardAvailabilityChangedNotification
) Darwin notification, but this is a private API, so it's possible your app will get rejected if you use this. To check if the external hardware is present, use the private GSEventIsHardwareKeyboardAttached()
function.
UIKit会监听此相应地设置 UIKeyboardImpl.isInHardwareKeyboardMode
属性,但这又是私有API。
UIKit listens to this and sets the UIKeyboardImpl.isInHardwareKeyboardMode
property accordingly, but again this is private API.
这篇关于如何检测iPad上是否有外接键盘?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!