How can I programmatically check whether a keyboard is present in iOS app?

Jitendra Singh picture Jitendra Singh · Sep 29, 2009 · Viewed 118.3k times · Source

I need to check the condition of keyboard visibility in my iOS app.

Pseudocode:

if(keyboardIsPresentOnWindow) {
    //Do action 1
}
else if (keyboardIsNotPresentOnWindow) {
    //Do action 2
}

How can I check this condition?

Answer

thpitsch picture thpitsch · Jun 10, 2012

…or take the easy way:

When you enter a textField, it becomes first responder and the keyboard appears. You can check the status of the keyboard with [myTextField isFirstResponder]. If it returns YES, then the the keyboard is active.