My IOS5, Iphone app uses a database, which I populate with data outside the app.
The app only opens the database file and reads the data, no insertion or updates.
App works fine in the simulator, but when I publish it to the iphone it crashes – I believe it is because database file wasn’t copied.
Currently file is on
/Users/stenio123/Library/Application Support/iPhone Simulator/6.0/Applications/4B3205EB-D98B-4D65-B22A-57E5E6A93F3C/MyAppName.app/MyDatabase.data
I I get the location path in the code by using
NSArray *documentDirectories =
NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,
NSUserDomainMask, YES);
NSString *documentDirectory = [documentDirectories objectAtIndex:0];
documentDirectory stringByAppendingPathComponent:@"MyDatabase.data"]
Which works on the simulator.
However what should I change so that it works on the real iPhone?
I tried dragging and dropping the MyDatabase.data file to XCode, making sure I checked “Copy items” and “add to target”. Then I changed the code above to the following variations
NSString *documentDirectory = @"/MyDatabaseFolder/";
NSString *documentDirectory = @"./MyDatabaseFolder/";
NSString *documentDirectory = @"MyDatabaseFolder/";
But none worked, not even in the simulator. Could you please advise?
Try add your database file to the application’s bundle by dragging it into your project, in Xcode, instead of just adding it to the document directory. From there, you can use it at will and it should be copied to the device. For example: