答案 0 :(得分:0)
您应该在应用程序包中添加sqlite文件(空白或预先存在),让应用程序知道它的存在并将其复制到文档目录中:
BOOL success;
NSArray*dirPath;
NSString*docDir;
dirPath=NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
docDir=[dirPath objectAtIndex:0];
databasePath=[docDir stringByAppendingPathComponent:@"yourDB.sqlite"];
NSFileManager*filemgr=[NSFileManager defaultManager];
success=[filemgr fileExistsAtPath:databasePath];
if(success)
{
NSLog(@"Already Present");
}
NSString* bundlePath=[[NSBundle mainBundle]pathForResource:@"yourDB" ofType:@"sqlite"];
NSError*error;
success=[filemgr copyItemAtPath:bundlePath toPath:databasePath error:&error];
if(success)
{
NSLog(@"Created Successfully");
}