在iPhone上模拟写入SQLite3
我有一个在模拟器中运行的应用程序。 我从 sqlite3 数据源读取和写入。 但是,如果我重新启动应用程序,那么我之前写入数据库的所有数据都会丢失。 数据始终处于其原始状态。
现在,当我开发这个应用程序时,我想我在某处读到数据无法通过 iPhone 模拟器保存。
有人能证实或否认这一点吗?
谢谢!
I have an app that is running in the simulator. I read and write from a sqlite3 data source. However, if i restart the app, then all datg that i had previously wrote to the db is lost.
The data is always in its original state.
Now back when i was developing this app i thought i read somewhere that data can not be persisted via iphone simulator.
Can anybody confirm or deny this?
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您需要将数据库文件放在可写的位置,例如在
Documents
文件夹中。 所有捆绑文件都是只读文件。如果您要随应用程序分发初始数据库,则需要将其复制到
Documents
(或其他文件夹)并使用该副本。您还需要确保在应用程序关闭时关闭数据库连接(即您收到
applicationWillTerminate
消息)。You need to place your db file in a writable place, e.g. in the
Documents
folder. All the bundle files are read-only files.If you are distributing an initial database with the app, you will need to copy it to
Documents
(or another folder) and use the copy.You also need to ensure that you close the database connection in your application is closing (i.e. you receive a
applicationWillTerminate
message).