Question

I'm working on UIDocument application and I'd like to show the user a preview of the document before he opens it. I can render that preview into an image when the document get's closed. But where should I save that image? In an other file? or is there a designated way to do this?

Right now I'm developing it without iCloud support. But I want to have a solution that would work with iCloud too. The UIDocument is a UIManagedDocument. But saving the image into the database would make it kind a pointless. Because then I have to open the document before I can get the preview.

What do you recommend here? Where to put a preview for a UIManagedDocument?

Was it helpful?

Solution

You should save an image under (app_directory)/Library/Caches. That way iCloud won't affect your app.

OTHER TIPS

You can store your documents in your ubiquity container's Documents directory and document preview files in the container's Data directory.

If preview file names will be based on the documents names you will be able to use metadata query result to get the document names and then resolve document preview urls.

This way you could download the document previews only but not the whole document.

I don't know about UIManagedDocuments, but in case of a UIDocument I would recommend using a NSFileWrapper as file format (where the document is actually a bundled folder) and save the preview within the document, as "Preview.jpg" (or .png) inside a folder labeled "QuickLook". This way, you'll get the preview in Finder on the Mac as well (for free).

Of course this may or may not be an ideal solution (also depending on if your document is text-only). But it might be a good hint for working with previews for UIDocuments in general.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top