开发者

database not being copied to the iPhone device from resources

I have come up with a strange problem. I am using sqlite database in my app. The app works fine when running in the simulator but when I deploy the app on iPhone device, it doesn't read from the db. Also, when I try to insert something to a table, it say no such table, which means that my db is not actually copied to the device. I hav tried cleaning the project with Build->Clean all Targets, delete the Build folder and manually remove the app from the device. Then try building again. but no luck. Certainly, I have added the db to the Resources and I can locat开发者_StackOverflowe and actually read the contents. Please guide me whats wrong when deploying on the device.


First check that you are copying the db into the bundle in the copy resources build phase. When a resource is in the bundle you cannot modify it, you need to copy it to the application's document directory

NSString *documentsDirectory = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0];


I actually never managed to get this right. That's why I've a build script setup that dumps any sqlite DB that i have into a .sql text file. On the first run of the app on the phone, i just generate the sqlite DB from these sql lines. Works much saver for me than working with the binary files from sqlite.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜