我使用的是“著名的” :)功能createEditableCopyOfDatabaseIfNeeded用于在iPhone应用程序创建我的数据库的可编辑副本。该功能复制的文件目录中的原始数据库只有在有没有数据库的副本..很简单..但现在我遇到了麻烦,因为我不知道为什么,但与SDK 3.2.3在iOS 4.1的功能复制我的数据库....空!
下面是代码:
- (void)createEditableCopyOfDatabaseIfNeeded
{
// First, test for existence.
BOOL success;
NSFileManager *fileManager = [NSFileManager defaultManager];
NSError *error;
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *writableDBPath = [documentsDirectory stringByAppendingPathComponent:@"funghi.sql"];
success = [fileManager fileExistsAtPath:writableDBPath];
if (success) return;
// The writable database does not exist, so copy the default to the appropriate location.
NSString *defaultDBPath = [[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:@"funghi.sql"];
success = [fileManager copyItemAtPath:defaultDBPath toPath:writableDBPath error:&error];
if (!success) {
NSAssert1(0, @"Failed to create writable database file with message '%@'.", [error localizedDescription]);
}
}
该数据库是完全正确! 我可以用Firefox的插件sqlite的阅读原文分贝! 任何帮助吗?
多谢!!!