开发者

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:

  1. Copy the file during runtime to your documents directory to make it writeable; or
  2. 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"]];
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜