4

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?

Malloc
  • 15,434
  • 34
  • 105
  • 192
Luca
  • 20,399
  • 18
  • 49
  • 70
  • Hope this help : [How to get Sqlite database file when application is running on device][1] [1]: http://stackoverflow.com/questions/6620691/how-to-get-sqlite-database-file-when-application-is-running-on-device – webmastx Jun 16 '12 at 06:23
  • No, the relative mapping of the path of a file is automatically done by iOS. There is no need to change your code for the device changes. It'll work fine for all the devices(including simulator). – Ananth Jun 16 '12 at 08:56
  • Ok, but why it's not recognizing the database file when i run on the device, does this mean my code is missing something ? – Luca Jun 16 '12 at 11:43

1 Answers1

4

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 :)

Malloc
  • 15,434
  • 34
  • 105
  • 192