【发布时间】:2012-03-02 05:09:12
【问题描述】:
我在资源中有一个名为 SketchImages 的子文件夹,其中包含 300 张 PNG 图像,我需要做的是在我的应用程序启动时将此文件夹复制到 iphone sdk 的文件夹中,我正在尝试以下代码但没有运气
BOOL success;
NSFileManager *fileManager = [[NSFileManager defaultManager] init];
NSError *error;
NSArray *paths = NSSearchPathForDirectoriesInDomains( NSDocumentDirectory,
NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *documentDBFolderPath = [documentsDirectory
stringByAppendingPathComponent:@"SketchImages"];
success = [fileManager fileExistsAtPath:documentDBFolderPath];
if (success)
{
return;
}else
{
NSString *resourceDBFolderPath = [[[NSBundle mainBundle] resourcePath]
stringByAppendingPathComponent:@"DB"];
//[fileManager createDirectoryAtPath: documentDBFolderPath attributes:nil];
[fileManager copyItemAtPath:resourceDBFolderPath toPath:documentDBFolderPath
error:&error];
}
任何帮助都会得到高度评价
【问题讨论】:
-
为什么要将所有图像复制到文档目录?它会增加您在 iphone 中的应用程序大小...
-
我正在写一本图画书,我需要这样做
-
调用 copyItemAtPath 时返回什么错误?
-
NSArray *paths = [[NSArray alloc] initWithArray:[[NSBundle mainBundle] pathsForResourcesOfType:@"png" inDirectory:nil]]; NSFileManager *fileManager = [[NSFileManager defaultManager] init]; NSArray *documentpaths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,NSUserDomainMask, YES); NSString *documentsDirectory = [documentpaths objectAtIndex:0]; NSString *documentDBFolderPath = [documentsDirectory stringByAppendingPathComponent:@"Images"]; NSError *错误; [[NSFileManager defaultManager] copyItemAtPath:[paths objectAtIndex:0] toPath:documentDBFolderPath error:err];
标签: iphone objective-c ios ios4