Reputation: 20919
I have an SQLite database file embedded into my project. On the simulator, querying the database works fine, but not on the device. My database file path when i run on the device is this (as shown on the console with an NSLog
) :
The path for the database file is : /var/mobile/Applications/5914F328-148F-52E6-1AC9-38D7FF141F9B/MyApplication.app/db.sqlite
My relevant code which looks for the DB is:
NSFileManager *fileMgr=[NSFileManager defaultManager];
NSString *dbPath=[[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:@"db.sqlite"];
NSLog(@"The path for the database file is : %@",dbPath);//Display the whole path
I know that the path on the simulator and on the device are completely different. So how should i change my code above to find my database file relatively?
Upvotes: 4
Views: 2147
Reputation: 16276
I solved my issue, for whom that struggle on the same problem, it needs me just to include my SQLite file db.sqlite
into my Bundle resources. CLick your project target-->Build Phases--->Copy Bundle Resources
and then hit the +
button and add your SQLite file or just drag your SQLite file from project Group and files and drop it there. Hope this help :)
Upvotes: 4