How to reliably detect if an external keyboard is connected on iOS 9?

前端 未结 9 708
隐瞒了意图╮
隐瞒了意图╮ 2020-12-02 13:05

Previous to iOS 9, the most reliable method of determining whether an external keyboard is connected was to listen for UIKeyboardWillShowNotification and make a

9条回答
  •  醉梦人生
    2020-12-02 14:03

    iOS 14 SDK finally brings public API for that: GCKeyboard. To check if external keyboard is connected:

    let isKeyboardConnected = GCKeyboard.coalescedKeyboard != nil
    

    Notes:

    • import GameController
    • you might need to enclose it in if #available(iOS 14.0, *)

提交回复
热议问题