Iamd eveloping one application.In that I used the sqlite datase.When iam running in simulator the data is saved in database.And there is no problem when iam retrieving th开发者_JAVA技巧at data.But when iam running in the device the process was killed at the time of retrieve the data.SO please tell me what i can do to solve this problem.
You should add sqlite file (blank or pre existing) in application bundle, and let the application know about its existance and copy it in Documents Directory:
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");
}
精彩评论