Copy local SQLite Database to iPhone?
i am doing some experiments with coredata and objective-c. My applicatio开发者_开发百科n works fine in the simulator.
It also works on my iPodTouch. But how to i copy my local database to my device?
thanks,
Copy the sqlite file out of the simulator directory structure (under ~/Library/Application Support/iPhone Simulator) and put it into your project to be included in the Resources directory. Once there you can either:
- Copy the file during runtime to your documents directory to make it writeable; or
- Reference it directly from within the app bundle to make it a read-only database
Depending on your application needs.
This is the solution (Thanks Marcus S. Zarra)
Change this
NSURL *storeUrl = [NSURL fileURLWithPath: [[self applicationDocumentsDirectory] stringByAppendingPathComponent: @"Locations.sqlite"]]
into this:
NSURL *storeUrl = [NSURL fileURLWithPath: [[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent: @"Locations.sqlite"]];
精彩评论