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