gpt4 book ai didi

ios - 如何检测 iPad 上是否存在外接键盘?

转载 作者:IT王子 更新时间:2023-10-29 07:36:29 26 4
gpt4 key购买 nike

有没有办法检测 iPad 是否连接了外接(蓝牙或 USB)键盘?

最佳答案

一种间接且 SDK 安全的方法是将文本字段设置为第一响应者。如果存在外部键盘,则不应发布 UIKeyboardWillShowNotification 本地通知。

Update: This is no longer true since iOS 9, however you may use the keyboard dimensions to determine if a hardware or software keyboard is involved. See How to reliably detect if an external keyboard is connected on iOS 9? for details.

您可以收听 "GSEventHardwareKeyboardAttached" (kGSEventHardwareKeyboardAvailabilityChangedNotification) Darwin 通知,但这是一个私有(private) API,因此如果您使用此 API,您的应用可能会被拒绝.要检查外部硬件是否存在,请使用私有(private) GSEventIsHardwareKeyboardAttached() 函数。

UIKit 监听此并相应地设置 UIKeyboardImpl.isInHardwareKeyboardMode 属性,但这同样是私有(private) API。

关于ios - 如何检测 iPad 上是否存在外接键盘?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2893267/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com