I want to use the autocorrection and shortcut list like default English keyboard with my custom keyboard. I check the in keyboard document but don\'t know how to use it.
In case anyone is still looking into this, I found a really nice C++ predictive text library called Presage. It seems to do a good job based on the demo but I'm having a lot of trouble trying to integrate it as a library (see my question here).
Let me know if anyone has any ideas, very interested in getting this working!
This is the way you can actually access Lexicon words:
[self requestSupplementaryLexiconWithCompletion:^(UILexicon *receivedLexicon) {
self.lexicon = receivedLexicon;
for (UILexiconEntry *word in self.lexicon.entries) {
// Text to be inserted into a text input object by a custom keyboard, corresponding to the userInput value in the same lexicon entry.
NSLog(@"%@",word.documentText);
// Text to match, during user input, to provide appropriate output to a text document from the documentText value in the same lexicon entry.
NSLog(@"%@",word.userInput);
}
}];
You can use below logic for AutoCorrect & it will also work in iOS 10
-(void)didClickAtAlphaNumericKeyboardKey:(NSString *)value {
if ([value isEqualToString:@" "]) {
UITextChecker *checker = [[UITextChecker alloc] init];
currentString = self.textDocumentProxy.documentContextBeforeInput;
NSCharacterSet *charSet = [NSCharacterSet whitespaceAndNewlineCharacterSet];
NSArray *components = [currentString componentsSeparatedByCharactersInSet:charSet];
NSString *lastWord = components.lastObject;
NSRange checkRange = NSMakeRange(0, lastWord.length);
NSRange misspelledRange = [checker rangeOfMisspelledWordInString:lastWord
range:checkRange
startingAt:checkRange.location
wrap:NO
language:@"en_US"];
NSArray *guessedWord = [checker guessesForWordRange:misspelledRange inString:lastWord language:@"en_US"];
if (guessedWord && guessedWord.count > 0) {
for (int i = 0; lastWord.length >i ; i++) {
[self.textDocumentProxy deleteBackward];
}
[self.textDocumentProxy insertText:[guessedWord objectAtIndex:0]];
}
}
[self.textDocumentProxy insertText:value];
}