简体   繁体   English

我的应用程序应该在iOS上存储大量PDF文件?

[英]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. 我正在编写一个iOS iPad应用程序,它将从网上下载数百个大型PDF文件并将其缓存在iPad上以供离线使用。

Where is the best place to store them on the iPad? 在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. 我计划将核心数据用于索引和搜索机制(使用缩略图等),并且只有在用户专门请求完整文档时才能访问PDF文档。

The best place to do so is either the Documents directory or the Cache directory. 这样做的最佳位置是Documents目录或Cache目录。 Documents in the Documents directory are supposed to be user-generated content, so I believe this is not what you're looking for. Documents目录中的文档应该是用户生成的内容,所以我相信这不是你想要的。

Instead, I think you should use the Cache directory, which you can access using this method : 相反,我认为您应该使用Cache目录,您可以使用此方法访问该目录:

- (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. 根据我的经验,这种情况几乎从未发生过,但是如果您想要绝对地保存文件永远不会被删除,您可能希望将文档存储在除Cache之外的Library目录的子目录中。

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. 在这种情况下,您必须在目录和文件上设置“ do not backup标志,否则您的应用程序被拒绝。

See the Apple guidelines (requires a developper account) for official information. 有关官方信息,请参阅Apple指南 (需要开发人员帐户)。

You should save them in the /documents folder. 您应该将它们保存在/ documents文件夹中。 The purpouse for that folder is exactly that, store data that couldn't be redownloaded (or would be too big to do so). 该文件夹的purpouse正是如此,存储无法重载的数据(或者太大而不能这样做)。 If it were temp data or data you could easily redownload, Apple suggests to use the /cache folder instead. 如果是临时数据或数据,您可以轻松重新下载,Apple建议使用/ cache文件夹。

You can save the files with a specific name, and just save that name in CoreData to find them back. 您可以使用特定名称保存文件,只需将该名称保存在CoreData中即可找回它们。

I would save the PDFs under the Documents folder. 我会将PDF保存在Documents文件夹下。 And create a core data sqlite datebase. 并创建一个核心数据sqlite数据库。 Create a core data entity with probably three attributes: thumbNail, localURL, and title. 创建一个核心数据实体,可能包含三个属性:thumbNail,localURL和title。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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