我想将文档从文档复制到iOS中的资源文件夹中。如何将文档中的文件复制到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中的资源?
感谢您的阅读。
你的意思是应用程序绑定? – J2theC 2012-08-17 17:35:37
yes.application包。 – MrDeveloper 2012-08-17 17:36:19
我该怎么做? – MrDeveloper 2012-08-17 17:38:42