'Detecting keyboard via GCKeyboard.coalesced at launch

At application launch, I send device configuration details to our server so we know what kinds of devices and settings (device OS, rotation, dark mode, dynamic type setting...) users have. I'm trying to collect data on hardware keyboard use. Broadly speaking this is easy, by looking at GCKeyboard.coalesced.

I'm finding that if I check that property at launch (application:didFinishLaunching), it always returns nil, even when a keyboard is attached. Even if I check via a long delay (dispatch_after 15 seconds), it is always nil.

At some point later, after some unknown period or activity, things work as expected. For example, if I check it after hiding then resuming the app (such as in application:willEnterForeground) the value usually returns non-nil.

Any idea why this delay occurs, and if so, how to force or catch a reliable response?

I know I can set up a GCKeyboard notification. I currently report all device configuration at once, soon after launch. I'd like to include the absence or presence of a hardware keyboard in that same call, rather than some subsequent call if a hardware keyboard is found.

For what it's worth, I'm testing this on a 2nd Gen iPad Pro with Apple's Magic Keyboard.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source