问题
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