xcode/ios:在安装时尝试将文件复制到缓存文件夹 [英] xcode/ios: trying to copy files to caches folder on install

查看:52
本文介绍了xcode/ios:在安装时尝试将文件复制到缓存文件夹的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当应用安装在设备上时,我正在尝试将一堆文件复制到我的应用的缓存文件夹中.我尝试使用 Copy Files阶段来实现此目的,但是我真的不知道要使用哪个路径作为目的地.

I'm trying to copy a bunch of files to my app's caches folder when the app is installed on the device. I tried to use the Copy Files phase to achieve this, but i don't really know which path to use for its destination.

这是正确的方法吗?还是根本不可能?

is this the right approach ... ? or is this not possible at all?

推荐答案

我不确定使用这种方法是否不可能.但是,您始终可以编写一种方法,在启动时将资源预加载到Caches目录中.这是示例代码:

I am not sure if it is impossible using this approach. However you can always write a method which preloads your resources on launch to Caches dir. Here's sample code:

NSString* path=[NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES) objectAtIndex:0];
path=[path stringByAppendingString:@"/plpart1.txt"];
NSError* error;
NSString* source=[[NSBundle mainBundle] pathForResource:@"pl_part1" ofType:@"txt"];
[[NSFileManager defaultManager] copyItemAtPath:source toPath:path error:&error];

这篇关于xcode/ios:在安装时尝试将文件复制到缓存文件夹的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆