简体   繁体   中英

Where should my application store large number of PDF files on iOS?

I am writing an iOS iPad app that will download several hundred large PDF files from the web and cache them on the iPad for offline use.

Where is the best place to store them on the iPad? The local file system, core data, or some other place? I am planning to use core data for an indexing and search mechanism (using thumbnail images etc), and will only access the PDF docs when a user specifically requests the full document.

The best place to do so is either the Documents directory or the Cache directory. Documents in the Documents directory are supposed to be user-generated content, so I believe this is not what you're looking for.

Instead, I think you should use the Cache directory, which you can access using this method :

- (NSString *)cacheDirectory {
{
    NSArray *pathList = NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES);
    NSString *path    = [pathList objectAtIndex:0];
    return path;
}

Note that the Cache directory can be emptied by the system if you don't have enough space on the device. In my experience this almost never happens, but you might want to store your documents in a subdirectory of the Library directory other than Cache if you want to be absolutely, absolutely sure that the files never ever get deleted.

In this case, you have to set the do not backup flag on both the directory and the files, or else your app will be rejected.

See the Apple guidelines (requires a developper account) for official information.

You should save them in the /documents folder. The purpouse for that folder is exactly that, store data that couldn't be redownloaded (or would be too big to do so). If it were temp data or data you could easily redownload, Apple suggests to use the /cache folder instead.

You can save the files with a specific name, and just save that name in CoreData to find them back.

I would save the PDFs under the Documents folder. And create a core data sqlite datebase. Create a core data entity with probably three attributes: thumbNail, localURL, and title.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM