文件放在哪里服务器能加载,离线H5工程文件应该放在沙盒哪里比较好呢?

项目需要从服务器下载打包好的H5工程文件,以便在没网的时候加载离线HTML.应该放在哪一个目录下比较合适呢?

官方文档还没更新,还是只有三个目录

efdae7066c59e979c63677af24d5ad05.png

Documents

Library

Temp

实际运行已经多了一个文件夹SystemData,不知道干嘛用的.

df07646b58ad4ab9a3f88618e2c57032.png

先看看官方文档说明

Documents/

Use this directory to store user-generated content. The contents of this directory can be made available to the user through file sharing; therefore, his directory should only contain files that you may wish to expose to the user.

//使用该目录存储用户产生的内容.用户通过文件分享可以访问该目录下面的内容.因此,该文件夹应该仅仅包含文件----你想向用户展示的文件

The contents of this directory are backed up by iTunes and iCloud.

//该目录下的内容,会被备份到iTunes和iCloud

我觉得项目的模板文件,没必要暴露给用户,只是项目加载的时候用到即可

Library/

This is the top-level directory for any files that are not user data files. You typically put files in one of several standard subdirectories. iOS apps commonly use the Application Support and Caches subdirectories; however, you can create custom subdirectories.

该目录是"不是用户数据"的文件的顶层文件夹.你应该把文件放到几个子目录下.iOS应用程序通常使用应用程序支持和缓存目录;但是,您可以创建自定义的子目录。

Use the Library subdirectories for any files you don’t want exposed to the user. Your app should not use these directories for user data files.

不应该存储用户数据

The contents of the Library directory (with the exception of the Caches subdirectory) are backed up by iTunes and iCloud.

会通过iTuns和iCloud备份

For additional information about the Library directory and its commonly used subdirectories, see The Library Directory Stores App-Specific Files.

Library文件夹存储app相关的文件

嗯,看起来挺符合我的需要

Library有四个子文件夹,文档和实际的又有一点不一样

文档

50dbe60038b06a0f5dd0e784953c2c93.png

实际

d49da22e57a77d900806fb05b2bbca4f.png

实际没有的就不看了,只看有的

Caches

Use this directory to write any app-specific support files that your app can re-create easily. Your app is generally responsible for managing the contents of this directory and for adding and deleting files as needed.

使用该目录写入任何app相关的支持文件(这些文件容易重复创建生成).需要自己管理该目录下面的文件的添加和删除

In iOS 2.2 and later, the contents of this directory are not backed up by iTunes or iCloud. In addition, the system removes files in this directory during a full restoration of the device.

在iOS2.2及之后,该目录的文件不会备份到iTunes和iCloud.此外,在设备恢复的时候,系统会移除该目录下的文件

In iOS 5.0 and later, the system may delete the Caches directory on rare occasions when the system is very low on disk space. This will never occur while an app is running. However, be aware that restoring from backup is not necessarily the only condition under which the Caches directory can be erased.

在iOS5.0及之后,在磁盘空间不足的时候,系统可能会删除该目录下的文件.当然这种情况不会发生在app还在运行的情况下.然而,必须意识到,从备份恢复不是该文件夹被抹去的必要的条件

总结一下,

可以存储app相关的的,容易重新生成的文件,并且手动管理添加和删除

不会备份到iTunes和iCloud,

有可能会被删除

感觉放在这里也是不妥当的,项目用到的离线模板html被删除了还要下载,下载的契机应该是服务器上版本更新了.

Preferences

这个就没什么好说的

会被备份到iTunes和iCloud

不应该自己往里面存东西,使用偏好设置NSUserDefaults相关api

因为可以在Library中自己创建文件夹,所以,我觉得在此处创建一个文件夹存放H5工程文件是不错的选择.其实我觉得放在Caches里面也可以,如果文件不是很大,下载不是很费劲,毕竟被删除的情况只是少数,文档这么讲嘛~

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值