Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use auto suggestion view for custom key-board extension ios8?

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 set BOOL yes in info.plist has access to a basic autocorrection lexicon through the UILexicon class. Make use of this class, along with a lexicon of your own design, to provide suggestions and autocorrections 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:

enter image description here

But still can't get access to a custom dictionary for word suggestions like Apple's iOS8 default keyboard does:

enter image description here

My custom keyboard look like:

enter image description here

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];
        }
    }];
}
like image 808
Nitin Gohel Avatar asked Sep 26 '14 05:09

Nitin Gohel


Video Answer


1 Answers

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:

enter image description here

like image 175
Nitin Gohel Avatar answered Sep 18 '22 15:09

Nitin Gohel