当应用程序版本在 iPhone 中的 Appstore 上更改时,sqlite 数据库更新 [英] sqlite database update when app version changes on Appstore in iPhone

查看:14
本文介绍了当应用程序版本在 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

推荐答案

我相信有很多方法可以做到这一点(而且很多方法也比我的好),但我处理这些问题的方法如下:

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:

首先,我在应用程序的第一个 .h 文件(将首先加载的文件)中定义一个常量以指示首次加载并将其设置为 0:

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:

#define FirstTime 0

现在您必须知道我打算将此常量的值保存在 Documents 文件夹中以供将来参考,因此我使用了共享数据实例.在 viewDidLoad 中,我做了以下测试:

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:

//if first time run of this version
if( [MyDataModel sharedInstance].count < (FirstTime + 1) )
{
    //do what you need to do as the first time load for this version

    [MyDataModel sharedInstance].count++
    //save the count value to disk so on next run you are not first time
    //this means count = 1
}

现在关键在于您的新应用版本(比如 1.1).我将 FirstTime 更改为 2:

Now the trick is on your new app version (say 1.1). I change the FirstTime to 2:

#define FirstTime 2

由于保存在光盘上的 First Time 值为 1,这意味着您将被上面的 if 语句捕获,因此您可以在其中执行任何操作,例如删除旧表并使用新格式重新创建它们.

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!

这篇关于当应用程序版本在 iPhone 中的 Appstore 上更改时,sqlite 数据库更新的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆