xcode 尝试在 iPhone 应用程序更新中覆盖 sqlite 数据库
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/5266967/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Trying to overwrite sqlite database in iPhone app update
提问by Benjamin
Unlike most sqlite apps where developers don't want to overwrite data in a sqlite database, I'm trying to enable an app to overwrite all data with future updates. The sqlite database will have the exact same name and have the same tables, I just want to be able to update the data contained in the database without making users delete the app and reinstall it. Is there an easy method to do this?
与大多数开发人员不想覆盖 sqlite 数据库中的数据的 sqlite 应用程序不同,我试图使应用程序能够在未来的更新中覆盖所有数据。sqlite 数据库将具有完全相同的名称和相同的表,我只是希望能够更新数据库中包含的数据,而无需让用户删除应用程序并重新安装它。有没有一种简单的方法可以做到这一点?
Thanks in advance!
提前致谢!
回答by Tom Harrington
A SQLite database file is just a normal file, so no special steps are needed. Get the path or URL to the file, and use NSFileManager's -removeItemAtPath:error:
or -removeItemAtURL:error:
. Then create the new database the same way you created the old one.
SQLite 数据库文件只是一个普通文件,因此不需要特殊步骤。获取文件的路径或 URL,并使用 NSFileManager 的-removeItemAtPath:error:
或-removeItemAtURL:error:
. 然后以与创建旧数据库相同的方式创建新数据库。