PC パソコン

How to Fix “GCKeyboardDidConnect: ‘Generic Keyboard’” in Xcode 27

When an iPhone or iPad has no physical keyboard attached, Xcode 27 Device Hub can still cause GCKeyboardDidConnect to fire and leave a “Generic Keyboard” in GCKeyboard.coalesced. This article covers the representative output, the confirmed trigger in the reported setup, the recommended recovery sequence, alternatives, and verification steps.

Representative log

=== Initial state ===
GCKeyboard.coalesced: nil
cannot add handler to 0 from 0 - dropping

=== GCKeyboardDidConnect #1 ===
notification.object: <GCKeyboard ... 'Generic Keyboard'>
GCKeyboard.coalesced: Optional(<GCKeyboard ...>)

After the phantom keyboard appears, attaching a real keyboard may not produce another GCKeyboardDidConnect notification, and detaching it may not produce GCKeyboardDidDisconnect.

Cause

In the Apple Developer Forums report, the trigger was Xcode 27 beta 5 Device Hub’s “Simulate Hardware Keyboard” option for a physical device. Device Hub exposed a virtual Generic Keyboard to the device, so the Game Controller framework correctly observed a keyboard-like connection even though no Bluetooth, USB, or Smart Connector keyboard was attached directly.

Apple documents GCKeyboard.coalesced as the keyboard currently connected to the device. Multiple keyboards are represented by one coalesced object. Apple also documents that the connect notification is posted for the first keyboard, while the disconnect notification is posted after the last keyboard disconnects. A persistent virtual keyboard therefore changes whether a real keyboard is considered the first or last connection.

Important: Do not assume the notification observer is faulty. First determine whether Device Hub is forwarding a virtual hardware keyboard to the device.

Affected conditions and versions

  • Reported with Xcode 27 beta 5
  • A physical iPhone or iPad connected through Device Hub
  • “Simulate Hardware Keyboard” enabled in Device Hub
  • No keyboard directly attached over Bluetooth, USB, or Smart Connector
  • Feedback ID: FB24269002

As of September 28, 2026, Apple has not published a fixed Xcode version for this exact behavior. Test later Xcode 27 builds independently rather than assuming that the issue remains or has been fixed.

Recommended fix

  1. Open Device Hub from Xcode.
  2. Select the affected physical device.
  3. Turn off Device > Keyboard > Simulate Hardware Keyboard.
  4. Close Device Hub completely.
  5. Quit Xcode.
  6. Restart Xcode and launch the app on the device again.

In the reported case, disabling the option alone was not enough. Restarting Device Hub and Xcode was required to remove the virtual keyboard state.

Inspect the state in code

import GameController

print("Initial GCKeyboard.coalesced:",
      GCKeyboard.coalesced as Any)

NotificationCenter.default.addObserver(
    forName: .GCKeyboardDidConnect,
    object: nil,
    queue: .main
) { notification in
    print("GCKeyboardDidConnect")
    print("notification.object:", notification.object as Any)
    print("GCKeyboard.coalesced:",
          GCKeyboard.coalesced as Any)
}

NotificationCenter.default.addObserver(
    forName: .GCKeyboardDidDisconnect,
    object: nil,
    queue: .main
) { notification in
    print("GCKeyboardDidDisconnect")
    print("notification.object:", notification.object as Any)
    print("GCKeyboard.coalesced:",
          GCKeyboard.coalesced as Any)
}

How to verify the fix

  1. Launch the app with no physical keyboard attached.
  2. Confirm that GCKeyboard.coalesced is nil.
  3. Attach a real keyboard and confirm that one GCKeyboardDidConnect notification arrives.
  4. Detach it and confirm that GCKeyboardDidDisconnect arrives and coalesced returns to nil.

Alternatives

  • Separate tests that require Device Hub keyboard forwarding from tests that detect real hardware keyboards.
  • Do not make critical behavior depend on connection state alone; validate actual input events where appropriate.
  • Launch the app directly on the device without Device Hub interaction and compare the results.

Cautions

  • The message cannot add handler to 0 from 0 - dropping is not sufficient to identify this cause by itself. Correlate it with GCKeyboardDidConnect and the Generic Keyboard object.
  • If a real keyboard is attached, a non-nil coalesced value is expected.
  • Disabling “Simulate Hardware Keyboard” may prevent Mac keyboard input from being forwarded through Device Hub.
  • The recovery sequence is documented by the forum reporter; Apple has not announced a fixed version for this exact report.

Summary

If Xcode 27 reports GCKeyboardDidConnect for a persistent Generic Keyboard, check Device Hub’s “Simulate Hardware Keyboard” setting. Turn it off, close Device Hub, and restart Xcode to clear the virtual keyboard state. Verify the result by attaching and detaching a real keyboard while observing both notifications and GCKeyboard.coalesced.

Official references