Danchez Danchez - 2 months ago 29
Objective-C Question

iOS Keyboard (inside UIRemoteKeyboardWindow) is Not Shown When UITextField Becomes First Responder in Touch ID Completion Block (iOS 10 only)

I've recently discovered a problem in my app that only seems to occur in the betas of iOS 10 where the iOS system keyboard does not display when programmatically triggering a text field to become first responder inside of a completion handler -- specifically the completion handler I get back from a Touch ID attempt.

The crazy part of this issue is, even though the keyboard is not shown, the area on the iPhone where the keyboard normally would be is still responding to touch inputs as if the user is typing on the keyboard!

After doing a lot of investigation and debugging into the issue, I stumbled across the fact that the

hidden
property is set to
YES
on the private
UIRemoteKeyboardWindow
that gets created after
becomeFirstResponder
is invoked on the text field. In other situations where I bring up the keyboard and output the value of that
hidden
property, it's set to
NO
.

Has anybody else run into this problem in iOS 10 (as of Beta 6)? If so, anybody found a solution to this? I tried manually setting the
hidden
value to
YES
on the window instance but that had no effect on it. I'm pretty much grasping at straws at this point.

Attachments:

Here's the output of the windows from the
UIApplication
instance when the text field becomes first responder outside of the Touch ID completion handler:

becomeFirstResponder outside of Touch ID completion

And when it becomes the first responder inside the Touch ID handler:

becomeFirstResponder inside of Touch ID completion

First Update

So I did not consider the
becomeFirstResponder
being done on the main thread before that some have pointed out, but unfortunately, it did not resolve the issue -- however, I did make some additional discoveries. The
hidden
window issue seems to stem from outputting the details of the
UIApplication
instance's windows immediately after issuing the
becomeFirstResponder
action. After doing that, I set a breakpoint on the
UITextField
editing callback and proceed to interact with the keyboard (that is invisible) -- and when I output the window details, it doesn't seem like the
hidden
property is ever set to
YES
(which can possibly rule out that property being set as the cause of the issue), but I still have an invisible keyboard! I started debugging the view hierarchy and below is a screenshot of what it looks like when I examine the keyboard window:

Debugging Keyboard Window #1

Debugging Keyboard Window #2

Hopefully you guys can what I just noticed which is the keys are present but there appears to be some white view blocking them from sight. The thing is, I don't even see those white views on my app screen. I just see what normally sits behind the keyboard when it's present.

Answer

As a temporary workaround, call becomeFirstResponder after a delay fixed this, however, not happy with the hacky solution.