??????????
??????????????????????屻???????????á????????????????????????????????????????????????????????????????????????????
????????????
??????documents???′??????test.sqlite??????????????User??User???username??password????varchar???????Ρ?
?????????:???SQLiteManager???????????????????????????????????????У?????????′???????????documents????

 

/**
*  ??????????????????
*/
-(void)createEditableCopyOfDatabaseIfNeeded
{
// ???ж? sandbox ????? documents ???????????????????????? test.sqlite
NSFileManager *fileManager = [NSFileManager defaultManager];
NSError *error;
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory?? NSUserDomainMask?? YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *writableDBPath = [documentsDirectory stringByAppendingPathComponent:@"test.sqlite"];
BOOL ifFind = [fileManager fileExistsAtPath:writableDBPath];
if (ifFind)
{
// NSLog(@"??????????");
return;
}
else{
NSLog(@"?????????????????");
}
// ???????????????????????????????
NSString *defaultDBPath = [[NSBundle mainBundle] pathForResource:@"test" ofType:@"sqlite"];
BOOL ifSuccess = [fileManager copyItemAtPath:defaultDBPath toPath:writableDBPath error:&error];
if (!ifSuccess) {
NSLog(@"Failed to create writable database file with message '%@'."?? [error localizedDescription]);
}else {
NSLog(@"createEditableCopyOfDatabaseIfNeeded ????????");
}
return;
}