When I test my app on the simulator everything works. But when I test the app on my iPhone, it doesn't load from the db.sqlite3 data base.
I tried every solution from the internet. I cleaned the app. I added the database to the build phrases - copy bundle resources etc. Can you help me? Is there any fails in my coding?
-(void)openDataBase{
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
dbPath = [documentsDirectory stringByAppendingString:@"db.sqlite3"];
//load it
NSFileManager *fileManager = [NSFileManager defaultManager];
NSString *pathInRessource = [[NSBundle mainBundle] pathForResource:@"db" ofType:@"sqlite3"];
//exist it?
if (![fileManager fileExistsAtPath:dbPath]) {
[fileManager copyItemAtPath:pathInRessource toPath:dbPath error:nil];
}
//open database
int result = sqlite3_open([dbPath UTF8String], &db);
if (result != SQLITE_OK) {
sqlite3_close(db);
return;
}
//if ok
NSLog(@"Data base opened");
}
sqlite3_open()returned and check that against sqlite.org/c3ref/c_abort.htmlfile:///var/mobile/Applications/...id.../Documents/YourDatabase.sqlite. Try copying the code to find a path from another source.BOOL, not a string. You should probably also not be swallowing the error like you are usingnil