I'm using QLPreviewController
for displaying different kind of documents. All this documents can be edited by returning QLPreviewItemEditingMode.createCopy
or QLPreviewItemEditingMode.updateContents
to previewController(_:editingModeFor:)
instance method of QLPreviewControllerDelegate
.
Everything works as expected when using QLPreviewItemEditingMode.updateContents
. When user edits document previewController(_:didUpdateContentsOf:)
method of QLPreviewControllerDelegate
is getting called and updated content can be accessed with the url that was passed to data source of QLPreviewController
.
Problem begins when I want to use QLPreviewItemEditingMode.createCopy
. When user stops editing document, previewController(_:didSaveEditedCopyOf:at:)
method of QLPreviewControllerDelegate
is getting called with modifiedContentsURL
parameter of type URL
. The first time this method is getting called I read the data from modifiedContentsURL
and I successfully retrieve it. But every other call after the first one gives back url that has no data to retrieve.
Object that conforms to QLPreviewControllerDelegate
protocol looks like this:
final class CustomQLPreviewDelegate: NSObject, QLPreviewControllerDelegate {
var onSave: ( (Data?) -> Void )?
func previewController(_ controller: QLPreviewController, editingModeFor previewItem: QLPreviewItem) -> QLPreviewItemEditingMode {
.createCopy
}
func previewController(_ controller: QLPreviewController, didSaveEditedCopyOf previewItem: QLPreviewItem, at modifiedContentsURL: URL) {
// nil everytime after the first call
let data = try? Data(contentsOf: modifiedContentsURL)
onSave?(data)
}
}
I also inspected edited document in Finder and its edited copy is generated after the first call, then removed after the second call and never created again in subsequent calls.
I just wanna make sure that I'm doing everything correct before reporting this as a bug to Apple.