我正在构建一个需要预加载内容的iPhone应用程序。呈现此内容是为了测试用户的知识,但用户不会对其进行修改。内容包括专有图像文件和pdf文件。
据我了解,最佳实践是将其存储在应用程序的Library或Documents目录中(请告知此假设是否正确)。在该应用程序的未来版本中,我可能希望通过API上传其他(而非替代)内容,但这不是初始版本的一部分。
我已经看过许多关于获取应用程序文档和库目录的路径以及对其进行读写的帖子和教程。这一切都是好和有用的,但不是我在这里寻找的东西。
我想将内容预先加载到Documents和/或Library目录中,以便最初用于模拟器,以在模拟器中测试应用程序;最终到发行版本。我本以为不用编写代码就可以通过XCode做到这一点。
我无法在Stack Overflow或网上的其他地方找到解决方案。欢迎任何指针,链接,解决方案。我在Swift 4.2中使用XCode 10.3。
请参阅《文件系统编程指南:文件系统基础知识》,该指南向我们展示:
The “data container” (including the Documents and the various Library folders) is for content generated/saved by the app. When, in Xcode, you mark resources as being part of the target, that becomes part of the bundle, and your app can retrieve it from there at runtime.
Theoretically, yes, you could copy data from the bundle to the Documents and/or Library folders, but, yes, you would have do that programmatically. It seems a bit wasteful to have two copies of these resources on the device, but you can do whatever you want. Generally, though, resources included in the bundle would just be be opened directly from there at runtime, not copying it to the data container (except for those cases where you would need to change it, because bundle contents are read-only).
仅供参考,有关文件系统的其他信息,请参阅iOS Storage Best Practices视频。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句