UIReferenceLibraryViewController hasDictionaryDefinition 仅适用于 iPhone 5s 上的模拟器 [英] UIReferenceLibraryViewController hasDictionaryDefinition only works in Simulator on iPhone 5s

查看:75
本文介绍了UIReferenceLibraryViewController hasDictionaryDefinition 仅适用于 iPhone 5s 上的模拟器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我调用此代码时:

NSString* word = @"hello";
bool response = [UIReferenceLibraryViewController dictionaryHasDefinitionForTerm:word];

...在 iPhone 5s 或更高版本上,我将正确的值转换为 'response'(一个布尔值,取决于变量 'word' 是否在本地字典中定义.在模拟器上执行大约需要 500 毫秒.

...on an iPhone 5s or above I get the correct value into 'response' (a bool depending on whether the variable 'word' is defined in the local dictionary or not. It takes about 500ms to execute on the simulator.

但是,当我在 iPhone 4s、5、6 或 6+ 模拟器(但不是 5s)上调用它时,它会立即返回为 false 并将以下内容写入日志:

However, when I call it on an iPhone 4s, 5, 6 or 6+ simulator (but not the 5s), then it immediately comes back as false and writes the following to the log:

 +[_UIDictionaryManager _availableDefinitionDictionaries] returned nil. 
Error: Error Domain=ASError Code=21 "The operation couldn’t be completed. 
(ASError error 21 - Unable to copy asset information)" 

字典功能应该适用于 iOS 5+.我没有任何 iPhone 4s/5/6/6+ 设备来测试这个.

The dictionary functionality should work on iOS 5+. I don't have any iPhone 4s/5/6/6+ devices to test this on.

这是怎么回事?

推荐答案

我想我最终找到了答案,那就是控制台中的消息试图说用户没有安装字典.

I think I found the answer in the end which is that the message in the console is trying to say that the user has no dictionary installed.

事实

[UIReferenceLibraryViewController dictionaryHasDefinitionForTerm:word];

返回假如果:

  • 这个词未定义
  • 没有安装字典

这实际上非常没有帮助.在我的特定英语应用用例中处理所有这些的策略是:

That's actually really quite unhelpful. My strategy for handling all this in my particular English-only app use-case is:

  1. 如果 [UIReferenceLibraryViewController dictionaryHasDefinitionForTerm:word] 返回 true,则调用当前的定义函数"并返回.

  1. If [UIReferenceLibraryViewController dictionaryHasDefinitionForTerm:word] returns true then call the present "definition function" and return.

但是,如果返回 false,则使用应在所有英语词典中定义的单词(例如the"或word")调用 dictionaryHasDefinitionForTerm.

However, if it returns false, then call dictionaryHasDefinitionForTerm with a word that should be defined in all English dictionaries, such as "the" or "word".

如果the"或word"返回true,则说明安装了词典,但在安装的词典中该词未定义.缓存the"/word"的结果,这样你就不必重复第 2 步,但不要永久保存它,因为用户或系统可能会删除字典 - 整个字典系统看起来非常有问题.

If "the" or "word" return true then there are dictionaries installed, but this word is undefined in the installed dictionaries. Cache the result of "the"/"word" so you don't have to repeat step 2 onwards, but don't save it permanently because the user or the system might delete the dictionary - the whole dictionary system seems very buggy.

如果the"或word"返回false,我们可以认为没有安装字典.此时我调用函数来呈现原始单词的定义(自然显示为无定义",但这是用户访问管理"词典功能以安装词典的唯一途径!),以及一个对话框,说明用户需要单击管理"并安装英文词典才能获得单词定义.

If "the" or "word" returns false we can take that to mean there are no dictionaries installed. At this point I call the function to present the definition of the original word (which is shown with "no definition" naturally, but it's the only way for the user to access the "manage" dictionaries function in order to install a dictionary!), together with a dialog box explaining that the user needs to click "manage" and install an english-language dictionary if they want word definitions.

离理想还有很长的路要走,但不确定在我的用例中我还能做什么.

A long way from ideal, but not sure what else I can do in my use-case.

这篇关于UIReferenceLibraryViewController hasDictionaryDefinition 仅适用于 iPhone 5s 上的模拟器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆