Nit*_*hel 7 iphone keyboard ios ios8 ios-keyboard-extension
如何在我自己的iOS8自定义键盘扩展中实现Apple的预测输入面板?
Apple的自定义键盘API Doc 自定义键盘 指出:
RequestsOpenAccessBOOL在info.plist中设置yes可以autocorrection通过UILexicon类访问基本词典.使用此类以及您自己设计的词典,suggestions以及autocorrections用户输入文本时.
但我找不到如何使用UILexicon我的自定义键盘.我将RequestsOpenAccess设置设置为YES:

但仍然无法访问自定义词典,如Apple的iOS8默认键盘这样的单词建议:

我的自定义键盘看起来像:

编辑:
我发现requestSupplementaryLexiconWithCompletion用于UILexicon class这样的我尝试使用以下代码实现这个:
- (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];
}
}];
}
Run Code Online (Sandbox Code Playgroud)
Finlay我做到了..!我使用sqlite静态数据库提出建议并使用类似查询得到前三个建议的工作,如下面的代码:
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];
}
Run Code Online (Sandbox Code Playgroud)
我得到了我的键盘输出是:

| 归档时间: |
|
| 查看次数: |
3301 次 |
| 最近记录: |