本文介绍了PDFKit 背景搜索的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用新的 iOS PDFKit 框架在后台线程上运行搜索.

I'm trying to run a search on a background thread using new iOS PDFKit framework.

override func main() {
    if isCancelled {
      return
    }
    pdfDocument = PDFDocument.init(url: book.document.url)!
    pdfDocument.delegate = self
    pdfDocument.beginFindString("test", withOptions: [.caseInsensitive, .diacriticInsensitive]) (async)
    //pdfDocument.findString("test", withOptions: [.caseInsensitive, .diacriticInsensitive]) (sync)

  }

问题是没有调用 PDFDocumentDelegate 的方法,如果我使用 TIME Profiler 似乎什么也没有发生.同步选项有效但无法取消.

The problem is that none of the PDFDocumentDelegate's methods isn't called and if I use the TIME Profiler nothing seems to happen. The sync option works but cannot be cancelled.

有什么想法吗?

推荐答案

委托方法适用于同步 findString.

Delegate methods will work fine for synchronous findString.

在异步 beginFindString 的情况下,你应该依赖通知:

In case of async beginFindString you should rely on notifications:

// Objective - C
PDFDocumentDidBeginFindNotification
PDFDocumentDidEndFindNotification
PDFDocumentDidBeginPageFindNotification
PDFDocumentDidEndPageFindNotification
PDFDocumentDidFindMatchNotification

// Swift
Notification.Name.PDFDocumentDidBeginFind
Notification.Name.PDFDocumentDidEndFind
Notification.Name.PDFDocumentDidBeginPageFind
Notification.Name.PDFDocumentDidEndPageFind
Notification.Name.PDFDocumentDidFindMatch

这篇关于PDFKit 背景搜索的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-19 01:49