简体   繁体   English

UIReferenceLibraryViewController hasDictionaryDefinition仅适用于iPhone 5s上的模拟器

[英]UIReferenceLibraryViewController hasDictionaryDefinition only works in Simulator on iPhone 5s

When I call this code: 当我调用此代码时:

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

...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 5s或更高版本上,我将正确的值输入'response'(bool取决于变量'word'是否在本地词典中定义。在模拟器上执行大约需要500ms。

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: 但是,当我在iPhone 4s,5,6或6+模拟器(但不是5s)上调用它时,它会立即返回为假并将以下内容写入日志:

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

The dictionary functionality should work on iOS 5+. 字典功能应该适用于iOS 5+。 I don't have any iPhone 4s/5/6/6+ devices to test this on. 我没有任何iPhone 4s / 5/6/6 +设备来测试这个。

What is going 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. 我想我最终找到了答案,即控制台中的消息试图说用户没有安装字典。

The fact that 这个事实

[UIReferenceLibraryViewController dictionaryHasDefinitionForTerm:word];

returns false if: 如果出现以下情况

  • The word is undefined 这个词是未定义的
  • There's no dictionaries installed 没有安装字典

That's actually really quite unhelpful. 这实际上真的非常无益。 My strategy for handling all this in my particular English-only app use-case is: 我在特定的英语应用程序用例中处理所有这些的策略是:

  1. If [UIReferenceLibraryViewController dictionaryHasDefinitionForTerm:word] returns true then call the present "definition function" and return. 如果[UIReferenceLibraryViewController dictionaryHasDefinitionForTerm:word]返回true,则调用当前的“定义函数”并返回。

  2. However, if it returns false, then call dictionaryHasDefinitionForTerm with a word that should be defined in all English dictionaries, such as "the" or "word". 但是,如果它返回false,则使用应在所有英语词典中定义的单词调用dictionaryHasDefinitionForTerm,例如“the”或“word”。

  3. If "the" or "word" return true then there are dictionaries installed, but this word is undefined in the installed dictionaries. 如果“the”或“word”返回true,则会安装字典,但在已安装的字典中未定义此单词。 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. 缓存“该”/“单词”的结果,这样您就不必重复步骤2,但不要永久保存,因为用户或系统可能会删除字典 - 整个字典系统似乎非常错误。

  4. If "the" or "word" returns false we can take that to mean there are no dictionaries installed. 如果“the”或“word”返回false,我们可以认为这意味着没有安装字典。 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. 离理想很远,但不知道我在用例中还能做些什么。

Not sure if this really answers the question but here's what you might be interested to know about: 不确定这是否真的回答了这个问题,但是您可能有兴趣了解以下内容:

  1. If you open UIReferenceLibraryViewController (even outside the app, eg from Safari) and tap Manage there to show the dictionary list (even without downloading anything), the error disappears for the current simulator. 如果您打开UIReferenceLibraryViewController (甚至在应用程序之外,例如来自Safari) 点击管理那里以显示字典列表(即使没有下载任何内容),当前模拟器的错误也会消失。
  2. Resetting Content and Settings on the simulator gets the error back — until you do #1 again. 在模拟器上重置内容和设置会收到错误 - 直到您再次执行#1。
  3. Strangely, on a device I constantly get YES in dictionaryHasDefinitionForTerm: , even if I then see "No definition found" in the controller. 奇怪的是,在设备上我经常在dictionaryHasDefinitionForTerm:得到YES dictionaryHasDefinitionForTerm:即使我在控制器中看到“找不到定义”。

Some of these must certainly be a bug :-) 其中一些肯定是一个bug :-)
I'm very curious to know if anyone has the same behaviour in #3 as it smells worse than littering in the logs. 我很好奇,知道是否有人在#3中有相同的行为,因为它闻起来比在日志中乱扔垃圾更糟糕。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM