Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Where to store a preview of a UIDocument?

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?

like image 905
V1ru8 Avatar asked Feb 06 '12 18:02

V1ru8


3 Answers

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.

like image 191
voromax Avatar answered Sep 20 '22 06:09

voromax


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.

like image 42
auco Avatar answered Sep 21 '22 06:09

auco


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

like image 38
Jorsh Avatar answered Sep 21 '22 06:09

Jorsh