PDFKit background search

喜你入骨 提交于 2020-06-12 15:52:08

问题


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)

  }

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.

Any ideas?


回答1:


Delegate methods will work fine for synchronous findString.

In case of async beginFindString you should rely on notifications:

// Objective - C
PDFDocumentDidBeginFindNotification
PDFDocumentDidEndFindNotification
PDFDocumentDidBeginPageFindNotification
PDFDocumentDidEndPageFindNotification
PDFDocumentDidFindMatchNotification

or

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


来源:https://stackoverflow.com/questions/46584298/pdfkit-background-search

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!