iPhone 中 Appstore 上的应用程序版本更改时 sqlite 数据库更新
我在应用程序商店中有一个版本为 1.0 的应用程序,它使用 sqlite 数据库来读取数据。
现在我想通过数据库文件中的更新将我的版本更新到 1.1。
当我在设备上安装应用程序时使用开发人员证书它没有更新数据库,因为数据库文件已存在于文档文件夹中,因此我必须手动删除该应用程序并再次安装它。
我的问题是,当任何用户更新应用程序时,数据库也会根据当前版本。
任何建议欢迎。
谢谢
I have an app with version 1.0 on app store which uses sqlite database for reading the data.
Now I want to update my version to 1.1 with update in database file.
While using developer certificate when I install app on device it did not update the database as the database file already exist in documents folder so i have to manually delete the app and install it again.
My question is, when any user update the app, will the database also get updated according the current version.
Any suggestions are welcome.
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我确信有很多方法可以做到这一点(也有很多方法比我的更好),但我处理此类问题的方法如下:
首先,我在应用程序的第一个 .h 文件中定义一个常量(将首先加载)以指示首次加载并将其设置为 0:
现在您必须知道我打算将此常量的值保存在 Documents 文件夹中以供将来参考,因此我使用共享数据实例。在
viewDidLoad
中,我进行了以下测试:现在的技巧在于您的新应用程序版本(例如 1.1)。我将
FirstTime
更改为 2:由于光盘上保存的 First Time 值为 1,这意味着您将被上面的 if 语句捕获,因此在其中您可以执行任何您想要的操作,例如删除旧表并用新的阵型再次重新创建它们。
再次不是那么出色,但解决了这个问题!
I am sure there are many ways to do this (and many ways better then mine as well), but the way that I handle such problems is as follows:
First I define a constant in the first .h file of the app (the one that will load first) to indicate First Time load and set it to 0:
Now you have to know that I have the intention to save the value of this constant in the Documents folder for future references, therefore I use a Shared Data Instance. In the
viewDidLoad
I do the following test:Now the trick is on your new app version (say 1.1). I change the
FirstTime
to 2:Since the saved First Time value on disc is 1 this means you will be caught by the if statement above, therefore inside it you can do anything you want like delete the old tables and recreate them again with the new formation.
Again not that brilliant, but solves the case!
此方法依赖于 NSUserDefaults。这个想法是从
NSUserDefaults
获取以前的应用程序版本号(如果存在)并将其与当前版本进行比较。如果以前的应用程序版本
<
比当前版本或者以前的版本为nil
,则代码执行数据库升级。这意味着即使应用程序已经在 AppStore 上发布,也可以使用此方法。它会在应用程序更新期间将数据库升级到新版本。这是一个plist文件:
有一个由版本号和一组sql组成的数组查询对应的升级版本。
假设之前的版本是 1.2,实际版本是 1.4,则代码仅执行从版本 1.2 到 1.4 的升级。如果以前的版本是 1.3,当前版本是 1.4,则代码仅执行从 1.3 到 1.4 的升级。
如果以前的版本为零,则代码执行升级到 1.1,然后升级到 1.2,然后升级到 1.3,最后升级到 1.4。
This approach relies on
NSUserDefaults
. The idea is to get the previous app version number(if exists) fromNSUserDefaults
and compare it with the current version.The code performs db upgrade if the previous app version
<
than current version or if the previous version isnil
. It means that this approach can be used even though the app was already published on the AppStore. It will upgrade database to the new version during the app update.This is a plist file:
There is an array which is composed of the version number and a set of sql queries for the corresponding upgrade version.
Suppose that a previous version is 1.2 and the actual version is 1.4 the code perform the upgrade only from the version 1.2 to 1.4. If the previous version is 1.3 and the current 1.4 the code performs upgrade only from 1.3 to 1.4.
If the previous version is nil the code performs upgrade to 1.1 then to 1.2 then to 1.3 and finally to 1.4.
您也可以使用 .plist :
并且您可以在应用程序启动中或在主视图控制器的视图控制器中调用该函数..您的选择。
希望有帮助。
You can use
.plist
as well:And you can call the function in application launch or in your main view controller's view controller.. your choice.
hope it helps.