我想將文檔從文檔複製到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