我想将文件从文档复制到 iOS 的资源文件夹中。
不是要记录的资源。
从文档到资源的文件。
所以我写了以下代码。
- (NSString *) getDBPath2
{
NSString *dbPath = [[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:@"Htoo.mp3"];
return dbPath;
}
- (void) copyDatabaseIfNeeded
{
NSFileManager *fileManager = [NSFileManager defaultManager];
NSError *error;
NSString *dbPath = [self getDBPath];
BOOL success = [fileManager fileExistsAtPath:dbPath];
if(success)
{
NSString *defaultDBPath = [[NSBundle mainBundle] resourcePath];
success = [fileManager copyItemAtPath:defaultDBPath toPath:dbPath error:&error];
if (!success)
NSAssert1(0, @"Failed to create writable database file with message '%@'.", [error localizedDescription]);
}
}
- (NSString *) getDBPath
{
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory , NSUserDomainMask, YES);
NSString *documentsDir = [paths objectAtIndex:0];
return [documentsDir stringByAppendingPathComponent:@"Htoo.mp3"];
}
当我编写上面的代码时,我收到了错误消息。
2012-08-17 23:55:03.482 TestProjects[1645:f803] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Failed to create writable database file with message 'The operation couldn’t be completed. (Cocoa error 516.)'.'
那么如何将文件从文档复制到 iOS 中的 Resource 中呢?
谢谢你的阅读。