xcode:如何在“文档”中保存文件编译/构建阶段的文件夹(不是通过“运行时的代码”)?

发布于 2024-11-24 21:25:15 字数 609 浏览 4 评论 0原文

我有很多 jpeg+png+html 文件要添加到我的应用程序中,当然,当我“构建”它时,我的所有资源文件都会添加/包含在 myApp mainBundle 文件夹中。

我希望能够在运行时通过代码修改我的一些资源,但是:

1)我们无法在 mainBundle 中的运行时通过代码“写入”文件

2)我们可以仅在“文档”中执行此操作文件夹(或临时文件,或...)

3)我们可以通过运行时代码复制“文档”文件夹中的文件

4)在将 mainBundle 文件复制到“文档”中后,我们无法删除它们,

但这意味着我们将有将我们的应用程序大小加倍,在大型应用程序中(这是我的情况)这应该是无意义的,我们将有很多大文件在 mainBundle 中不再使用......

所以我想知道是否有一个工作-围绕这个问题(只是我认为这是无意义的吗?)通过 xCode 或其他类似的解决方案直接在“构建”阶段的“文档”文件夹中添加文件...

ps

一个可能是下载所有用户第一次使用时的文件我的应用程序通过服务器/互联网直接在“文档”文件夹中,因此通过 iTunesStore 下载我的应用程序不会很繁重,但是当然,这对于最终用户来说第一次会花费很多时间,而且可能不太好接受了,当然……

I have a lot of jpeg+png+html files to add to my app, and of course when i "build" it all my resources files are added/included in myApp mainBundle folder.

I'd like to be able to modify via code, in run time, some of my resources, but:

1) we cannot "write" files via code in run-time in mainBundle

2) we can do it just in "documents" folder (or temp, or...)

3) we can copy files in "Documents" folder just via code in run-time

4) we cannot delete the mainBundle files after coping them in "Documents"

but that means that we will have doubled-sized our app, and in big apps (it's my case) this should be a non-sense, we'll have a lot of big files never used again in the mainBundle...

so i wondered if there was a work-around for this problem (is it just me thinking it's a non-sense?) to add files directly in the "Documents" folder in the "build" phase via xCode, or other similar solutions...

ps

one could be to download all files the first time a user use my app via server/internet directly in "Documents" folder, so my app won't be heavy to download via iTunesStore, but of course this will get a lot of time the first time for end-users, and it could be not well accepted, of course...

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

爱的那么颓废 2024-12-01 21:25:15

嗯,你不能,因为文档目录是在安装应用程序时创建的。没有办法在编译时做你想做的事情。您也不能在安装时执行此操作。

由于您需要该文件,因此必须将它们包含在捆绑包中,我什至包含了 10MB sqlite 数据库,我在第一次启动时直接将其复制到文档中。事情就是这样。

Well you can't, since the document directory is created on installing the app. There is no way to do what you want on compile time. Neither you can do it at the install.

Since you needed the file you have to include them in your bundle, i've even included 10MB sqlite database that I copy to to the document direct on first launch. That is just the way it is.

可是我不能没有你 2024-12-01 21:25:15

不适用于应用程序

在编译时将文件复制到文档目录需要您提前知道该目录。您通常无法知道这一点,因为在安装应用程序之前可能尚未创建文档目录。

可以在模拟器上进行单元测试

但是,文档目录的位置取决于目标平台和您正在构建的捆绑包类型。对于在 iOS 模拟器上执行的基于 SenTestingKit 的单元测试,您可以通过在“运行脚本”构建阶段中执行此操作来确定编译时的文档目录:

~/Library/Application Support/iPhone\ Simulator/$IPHONEOS_DEPLOYMENT_TARGET/Documents

请注意,这实际上仅适用于单元测试包,因为它们不会在专用的应用程序目录,从而访问模拟器平台上的“共享”文档目录。

Doesn't work for apps

Copying files to the documents directory during compile time requires you to know that directory in advance. You generally can't know this as the documents directory might not have been created before your app is installed.

Can work for unit tests on the simulator

However, the location of the documents directory depends on the target platform and the kind of bundle you are building. For unit tests based on SenTestingKit executed on the iOS simulator, you can determine the documents directory at compile time by just doing this inside a "Run Script" build phase:

~/Library/Application Support/iPhone\ Simulator/$IPHONEOS_DEPLOYMENT_TARGET/Documents

Note that this really only works for unit test bundles as those are not executed in a dedicated app directory and thus access a "shared" documents directory on the simulator platform.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文