I would like to know if there is any way to check wether predictive text (the grey boxes above the keyboard) are enabled.
I need this to scoll a view a few pixel more to the top when the textfield gets its focus. I get the size of the keyboard with: CGSize kbSize = [[info objectForKey:UIKeyboardFrameBeginUserInfoKey] CGRectValue].size;
Accept or reject a predictive text suggestion While typing text, you can do either of the following: Accept a suggested word or emoji by tapping it; accept a highlighted suggestion by entering a space or punctuation. When you tap a suggested word, a space appears after the word.
If you're using an Android, the language varies, but you should find settings for your keyboard in Settings > General > Language and Input > Keyboard Preferences (you might have to pick a keyboard) > Text Correction (might be called Word Suggestion). Tap the switch to toggle it on.
@1Papillon: To troubleshoot your issue please go to Settings > General Management > Language and Input > On-Screen Keyboard > Samsung Keyboard > Smart Typing > Make Sure that Predictive Text is toggled on > Back > About Samsung Keyboard > Tap the 'i' in the top right > Storage > Clear Cache > Clear Data > Restart your ...
Use end frame to get the last position the keyboard will end up. So in your keyboardWillShow:
notification callback get the keyboard end frame.
- (void)keyboardWillShow:(NSNotification *)notification
{
NSDictionary *userInfo = notification.object;
CGRect keyboardEndFrame;
[[userInfo objectForKey:UIKeyboardFrameEndUserInfoKey] getValue:&keyboardEndFrame];
// Use keyboardEndFrame
}
This even works when user resizes the predictive text view (shrink/expand) and also works if you have an input accessory view.
The real answer to the title of this question is different. As of now, there is no obvious way to find out if the predictive text is enabled. So I came up a solution which checks keyboard frame with different autocorrection types.
#import <UIKit/UIKit.h>
@interface ZSTKeyboardChecker : NSObject
- (BOOL)isPredictiveTextEnabledForTextField:(UITextField *)textField;
@end
@interface ZSTKeyboardChecker ()
@property (assign, nonatomic) CGRect keyboardEndFrame;
@end
@implementation ZSTKeyboardChecker
- (void)dealloc
{
[[NSNotificationCenter defaultCenter] removeObserver:self];
}
- (instancetype)init
{
self = [super init];
if (self) {
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillShow:) name:UIKeyboardWillShowNotification object:nil];
}
return self;
}
- (BOOL)isPredictiveTextEnabledForTextField:(UITextField *)textField
{
if (textField.autocorrectionType == UITextSpellCheckingTypeNo) {
return NO;
}
BOOL isFirstResponder = [textField isFirstResponder];
BOOL autoCorrectionType = [textField autocorrectionType];
[textField resignFirstResponder];
// Get the frame with possibly including predictive text
[textField becomeFirstResponder];
CGRect predictiveKeyboardEndFrame = self.keyboardEndFrame;
[textField resignFirstResponder];
// Get the keyboard frame without predictive text
textField.autocorrectionType = UITextSpellCheckingTypeNo;
[textField becomeFirstResponder];
CGRect defaultKeyboardEndFrame = self.keyboardEndFrame;
[textField resignFirstResponder];
// Restore state
textField.autocorrectionType = autoCorrectionType;
if (isFirstResponder) {
[textField becomeFirstResponder];
}
BOOL isPredictiveTextEnabled = !CGPointEqualToPoint(predictiveKeyboardEndFrame.origin, defaultKeyboardEndFrame.origin);
return isPredictiveTextEnabled;
}
- (void)keyboardWillShow:(NSNotification *)notification
{
NSDictionary *userInfo = notification.object;
CGRect keyboardEndFrame;
[[userInfo objectForKey:UIKeyboardFrameEndUserInfoKey] getValue:&keyboardEndFrame];
self.keyboardEndFrame = keyboardEndFrame;
}
@end
- (void)viewDidAppear:(BOOL)animated
{
[super viewDidAppear:animated];
ZSTKeyboardChecker *keyboardChecker = [[ZSTKeyboardChecker alloc] init];
BOOL isPredictiveTextEnabled = [keyboardChecker isPredictiveTextEnabledForTextField:self.textField];
NSLog(@"Enabled: %d", isPredictiveTextEnabled);
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With