How to detect when keyboard is shown and hidden
In the ViewDidLoad method of your class set up to listen for messages about the keyboard:
// Listen for keyboard appearances and disappearances
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(keyboardDidShow:)
name:UIKeyboardDidShowNotification
object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(keyboardDidHide:)
name:UIKeyboardDidHideNotification
object:nil];
Then in the methods you specify (in this case keyboardDidShow
and keyboardDidHide
) you can do something about it:
- (void)keyboardDidShow: (NSNotification *) notif{
// Do something here
}
- (void)keyboardDidHide: (NSNotification *) notif{
// Do something here
}
Programmatically check if iPhone keyboard is on screen or not
Basically, you want to add an NSNotificationCenter
observer:
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardDidShow) name:UIKeyboardDidShowNotification object:nil];
How to programaticly check with swift if keyboard is visible in ios app
There are UIKeyboardWillShowNotification
and UIKeyboardWillHideNotification
notifications of NSNotificationCenter
. Just subscribe to them
How to detect whether custom keyboard is activated from the keyboard's container app?
Here is a method I have used in one of my projects. I think it is what you asked for, hope it helps you.
- (BOOL)isCustomKeyboardEnabled {
NSString *bundleID = @"com.company.app.customkeyboard"; // Replace this string with your custom keyboard's bundle ID
NSArray *keyboards = [[[NSUserDefaults standardUserDefaults] dictionaryRepresentation] objectForKey:@"AppleKeyboards"]; // Array of all active keyboards
for (NSString *keyboard in keyboards) {
if ([keyboard isEqualToString:bundleID])
return YES;
}
return NO;
}
How can I detect if an external keyboard is present on an iPad?
An indirect and SDK-safe way is to make a text field a first responder. If the external keyboard is present, the UIKeyboardWillShowNotification
local notification shall not be posted.
Update: This is no longer true since iOS 9, however you may use the keyboard dimensions to determine if a hardware or software keyboard is involved. See How to reliably detect if an external keyboard is connected on iOS 9? for details.
You can listen to the "GSEventHardwareKeyboardAttached"
(kGSEventHardwareKeyboardAvailabilityChangedNotification
) Darwin notification, but this is a private API, so it's possible your app will get rejected if you use this. To check if the external hardware is present, use the private GSEventIsHardwareKeyboardAttached()
function.
UIKit listens to this and sets the UIKeyboardImpl.isInHardwareKeyboardMode
property accordingly, but again this is private API.
Within an iOS app how do I detect that the user has pressed one of the arrow keys on their external keyboard?
Not actually knowing, I suspect the answer is "you can't, not in an official way".
Since a user-friendly UI is top priority for the iPad platform according to Apple, I think they are doing what they can to discourage behavior that would depend on a keyboard being available. Apps should behave the same and provide the same functionality with or without a hardware keyboard. Things like keyboard hotkeys or navigation that doesn't use on-screen elements are probably no-no:s for that reason.
But, like I said, this is just speculation.
Related Topics
Ios App With Arc, Find Who Is Owner of an Object
Stringbyappendingpathcomponent Is Unavailable
Firebase Notification Records/Log API
Xcode 6: Keyboard Does Not Show Up in Simulator
Uibutton Custom Font Vertical Alignment
The Model Used to Open the Store Is Incompatible With the One Used to Create the Store
How to Customize the Background Color of a Uitableviewcell
How to Write Text on Image in Objective-C (Ios)
When to Use Dequeuereusablecellwithidentifier VS Dequeuereusablecellwithidentifier: Forindexpath
Uitapgesturerecognizer Breaks Uitableview Didselectrowatindexpath
Dealing With Different iOS Device Resolutions in Spritekit
How to Get the Day of the Week With Foundation
In Swift, How to Declare a Variable of a Specific Type That Conforms to One or More Protocols
How to Run App in Simulator: Xcode Beta 6 iOS 8