How can I implement Apple's predictive input panel in my own iOS8 custom keyboard extension?
Apple's Custom Keyboards API Doc Custom Keyboard states:
RequestsOpenAccess
setBOOL
yes in info.plist has access to a basicautocorrection
lexicon through the UILexicon class. Make use of this class, along with a lexicon of your own design, to providesuggestions
andautocorrections
as users are entering text.
But i can't find how to use the UILexicon
in my custom keyboard. I set the RequestsOpenAccess
setting to YES
:
But still can't get access to a custom dictionary for word suggestions like Apple's iOS8 default keyboard does:
My custom keyboard look like:
EDIT:
i Found requestSupplementaryLexiconWithCompletion
that used for UILexicon class
like this i try to implement this using following code:
- (void)viewDidLoad {
[super viewDidLoad];
[self requestSupplementaryLexiconWithCompletion:^(UILexicon *appleLex) {
appleLexicon = appleLex;
NSUInteger lexEntryCount = appleLexicon.entries.count;
for(UILexiconEntry *entry in appleLexicon.entries) {
NSString *userInput = [entry userInput];
NSString *documentText = [entry documentText];
lable.text=userInput;
[lable setNeedsDisplay];
}
}];
}
Finlay i done it..! i put suggestion using sqlite static database in and get first three suggested work using like query like following code:
NSString *precedingContext = self.textDocumentProxy.documentContextBeforeInput; //here i get enter word string.
__block NSString *lastWord = nil;
[precedingContext enumerateSubstringsInRange:NSMakeRange(0, [precedingContext length]) options:NSStringEnumerationByWords | NSStringEnumerationReverse usingBlock:^(NSString *substring, NSRange subrange, NSRange enclosingRange, BOOL *stop) {
lastWord = substring;
*stop = YES;
}];
NSLog(@"==%@",lastWord); // here i get last word from full of enterd string
NSString *str_query = [NSString stringWithFormat:@"select * from suggestion where value LIKE '%@%%' limit 3",lastWord];
NSMutableArray *suggestion = [[DataManager initDB] RETRIVE_Playlist:str_query];
NSLog(@"arry %@",suggestion); i get value in to array using like query
if(suggestion.count>0)
{
if(suggestion.count==1)
{
[self.ObjKeyLayout.FirstButton setTitle:[suggestion objectAtIndex:0] forState:UIControlStateNormal];
}
else if(suggestion.count==2)
{
[self.ObjKeyLayout.FirstButton setTitle:[suggestion objectAtIndex:0] forState:UIControlStateNormal];
[self.ObjKeyLayout.secondButton setTitle:[suggestion objectAtIndex:1] forState:UIControlStateNormal];
}
else
{
[self.ObjKeyLayout.FirstButton setTitle:[suggestion objectAtIndex:0] forState:UIControlStateNormal];
[self.ObjKeyLayout.secondButton setTitle:[suggestion objectAtIndex:1] forState:UIControlStateNormal];
[self.ObjKeyLayout.thirdButton setTitle:[suggestion objectAtIndex:2] forState:UIControlStateNormal];
}
}
else
{
[self.ObjKeyLayout.FirstButton setTitle:@"" forState:UIControlStateNormal];
[self.ObjKeyLayout.secondButton setTitle:@"" forState:UIControlStateNormal];
[self.ObjKeyLayout.thirdButton setTitle:@"" forState:UIControlStateNormal];
}
and i got it my keyboard output is:
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