UIReferenceLibraryViewController.dictionaryHasDefinition-**返回结果的速度非常慢-iOS 13(模拟器和真实设备)-Xcode 11

Dav*_*d K 11 performance uikit swift ios13

刚推出iOS 13时,我正在Xcode 11 GM2中测试我的应用程序,它使用您可以在iPhone上启用的字典进行单词查找。iOS12上的性能已经实现,几乎是瞬时的。

但是,这似乎已随着iOS 13发生了变化。下面的代码是相当标准的,需要3秒钟来响应!!!这在iOS13模拟器和带有iOS13的真实设备上均会发生。

我还没有看到任何有关iOS13 SDK或Xcode 11问题的报道。

这可能是需要报告的错误吗?还是我做错了什么。

这使我的应用看起来无响应。我该如何处理?

这很容易重现,并且与iOS 12.x模拟器相同的代码可以正常工作。

我的代码如下:

import UIKit

//I'm using storyboard with 1 button.

class ViewController: UIViewController {

    @IBOutlet weak var buttonTestUIRefVC: UIButton!

    @IBAction func testUIRefVCTapped(_ sender: UIButton) {

        if UIReferenceLibraryViewController.dictionaryHasDefinition(forTerm: "test") {
            let referenceVC = UIReferenceLibraryViewController(term: "test")
            present(referenceVC, animated: true)
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

从上面的代码,该位 UIReferenceLibraryViewController.dictionaryHasDefinition(forTerm: "test")是引入3秒延迟的原因。

这是调试日志的一部分,我之前没有看过那些“旧状态:1新状态:1”语句,它们仅在iOS 13中显示。这是什么意思?

2019-09-20 09:38:09.175923+0100 DictionaryServicesTest[18527:3511667] Creating client/daemon connection: C94E0479-7F79-4E22-895D-7F1FEFB75C8E
2019-09-20 09:38:09.201599+0100 DictionaryServicesTest[18527:3511667] Got the query meta data reply for: com.apple.MobileAsset.DictionaryServices.dictionary2, response: 0
2019-09-20 09:38:09.218045+0100 DictionaryServicesTest[18527:3511667] Old state: 1 new state:1
2019-09-20 09:38:09.226942+0100 DictionaryServicesTest[18527:3511667] Old state: 1 new state:1
2019-09-20 09:38:09.235839+0100 DictionaryServicesTest[18527:3511667] Old state: 1 new state:1
2019-09-20 09:38:09.244599+0100 DictionaryServicesTest[18527:3511667] Old state: 1 new state:1
2019-09-20 09:38:09.253388+0100 DictionaryServicesTest[18527:3511667] Old state: 1 new state:1
2019-09-20 09:38:09.262388+0100 DictionaryServicesTest[18527:3511667] Old state: 1 new state:1
2019-09-20 09:38:09.271329+0100 DictionaryServicesTest[18527:3511667] Old state: 1 new state:1
2019-09-20 09:38:09.280346+0100 DictionaryServicesTest[18527:3511667] Old state: 1 new state:1
2019-09-20 09:38:09.289581+0100 DictionaryServicesTest[18527:3511667] Old state: 1 new state:1
2019-09-20 09:38:09.298508+0100 DictionaryServicesTest[18527:3511667] Old state: 1 new state:1
2019-09-20 09:38:09.307121+0100 DictionaryServicesTest[18527:3511667] Old state: 1 new state:1
2019-09-20 09:38:09.339668+0100 DictionaryServicesTest[18527:3511667] [Client] Synchronous remote object proxy returned error: Error Domain=NSCocoaErrorDomain Code=4099 "The connection to service on pid 0 named com.apple.commcenter.coretelephony.xpc was invalidated." UserInfo={NSDebugDescription=The connection to service on pid 0 named com.apple.commcenter.coretelephony.xpc was invalidated.}
2019-09-20 09:38:09.339682+0100 DictionaryServicesTest[18527:3511797] [Client] Updating selectors failed with: Error Domain=NSCocoaErrorDomain Code=4099 "The connection to service on pid 0 named com.apple.commcenter.coretelephony.xpc was invalidated." UserInfo={NSDebugDescription=The connection to service on pid 0 named com.apple.commcenter.coretelephony.xpc was invalidated.}
2019-09-20 09:38:09.339880+0100 DictionaryServicesTest[18527:3511797] [Client] Updating selectors after delegate addition failed with: Error Domain=NSCocoaErrorDomain Code=4099 "The connection to service on pid 0 named com.apple.commcenter.coretelephony.xpc was invalidated." UserInfo={NSDebugDescription=The connection to service on pid 0 named com.apple.commcenter.coretelephony.xpc was invalidated.}
2019-09-20 09:38:09.352755+0100 DictionaryServicesTest[18527:3511667] Old state: 2 new state:2
2019-09-20 09:38:09.353305+0100 DictionaryServicesTest[18527:3511667] Consumed extension
2019-09-20 09:38:09.364478+0100 DictionaryServicesTest[18527:3511667] Old state: 2 new state:2
2019-09-20 09:38:09.373088+0100 DictionaryServicesTest[18527:3511667] Old state: 1 new state:1
2019-09-20 09:38:09.382055+0100 DictionaryServicesTest[18527:3511667] Old state: 1 new state:1
2019-09-20 09:38:09.391300+0100 DictionaryServicesTest[18527:3511667] Old state: 1 new state:1

......


2019-09-20 09:38:10.298739+0100 DictionaryServicesTest[18527:3511667] Old state: 1 new state:1
2019-09-20 09:38:10.308036+0100 DictionaryServicesTest[18527:3511667] Old state: 1 new state:1
2019-09-20 09:38:10.331372+0100 DictionaryServicesTest[18527:3511667] Got the query meta data reply for: com.apple.MobileAsset.DictionaryServices.dictionary2, response: 0
2019-09-20 09:38:10.347474+0100 DictionaryServicesTest[18527:3511667] Old state: 1 new state:1
2019-09-20 09:38:10.356643+0100 DictionaryServicesTest[18527:3511667] Old state: 1 new state:1

.....

2019-09-20 09:38:11.357946+0100 DictionaryServicesTest[18527:3511667] Old state: 1 new state:1
2019-09-20 09:38:11.367701+0100 DictionaryServicesTest[18527:3511667] Old state: 1 new state:1
2019-09-20 09:38:11.377362+0100 DictionaryServicesTest[18527:3511667] Old state: 1 new state:1
2019-09-20 09:38:11.387062+0100 DictionaryServicesTest[18527:3511667] Old state: 1 new state:1
2019-09-20 09:38:11.396676+0100 DictionaryServicesTest[18527:3511667] Old state: 1 new state:1
2019-09-20 09:38:11.406346+0100 DictionaryServicesTest[18527:3511667] Old state: 1 new state:1
2019-09-20 09:38:11.433850+0100 DictionaryServicesTest[18527:3511667] Got the query meta data reply for: com.apple.MobileAsset.DictionaryServices.dictionary2, response: 0
2019-09-20 09:38:11.450337+0100 DictionaryServicesTest[18527:3511667] Old state: 1 new state:1
2019-09-20 09:38:11.459251+0100 DictionaryServicesTest[18527:3511667] Old state: 1 new state:1



....


2019-09-20 09:38:12.490703+0100 DictionaryServicesTest[18527:3511667] Old state: 1 new state:1
2019-09-20 09:38:12.500646+0100 DictionaryServicesTest[18527:3511667] Old state: 1 new state:1
2019-09-20 09:38:12.510725+0100 DictionaryServicesTest[18527:3511667] Old state: 1 new state:1
Run Code Online (Sandbox Code Playgroud)

小智 1

尝试更新到iPadOS 14.0,我发现这个问题消失了。