0
我有一个应用程序,我试图将几个不同的表保存到文档目录。第一个节省罚款,但其他节点没有。我一直在研究,并没有发现任何说我不能这样做的事情。希望有人能够阐明一些看法。我使用的代码是典型的“CreateEditableCopyOfDatabaseIfNeeded”,但正如我所说,我有几个版本,这取决于我试图保存哪个数据库。下面的代码是第二个与“无法打开数据库”无效的工作。 在此先感谢。保存多个sqlite3数据库到文档目录
- (void)createEditableCopyOfScheduleDatabaseIfNeeded
{
//test if DB already exist
BOOL success;
NSFileManager *fileManager = [NSFileManager defaultManager];
NSError *error;
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
//save new DB's
NSString *writableScheduleDBPath = [documentsDirectory stringByAppendingPathComponent:@"schedulelist.sqlite3"];
NSLog(@"writable Schedule path:%@", writableScheduleDBPath);
success = [fileManager fileExistsAtPath:writableScheduleDBPath];
if (!success)
NSLog(@"Failure to open Schedule DB");
if (success) return;
//the writable database does not exist, so copy the default to the appropriate location
NSString *defaultScheduleDBPath = [[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:@"schedulelist.sqlite3"];
NSLog(@"default Schedule path:%@", defaultScheduleDBPath);
success = [fileManager copyItemAtPath:defaultScheduleDBPath toPath:writableScheduleDBPath error:&error];
if (!success)
NSAssert1(0, @"Failed to create Schedule writable database:%@", [error localizedDescription]);
}
不知道发生了什么,但重新启动后,似乎一切正常。必须清除doc目录。 – LittlePeculiar