对应用程序更新iPhone数据迁移 [英] Iphone data migration on application update

查看:210
本文介绍了对应用程序更新iPhone数据迁移的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的工作对使用SQLite的存储应用程序和用户数据的iPhone应用程序。

I am working on an iphone application that uses sqlite to store application and user data.

这是应用程序的第一个版本,我不知道我需要做的prepare为应用程序的未来版本。

This is the first version of the application and I wonder what I need to do to prepare for the future versions of the app.

这还不够吗?
1.确保应用程序的版本在X code项目设置正确
2.添加在源码文件版本号,以便它可以在以后读

Is this enough? 1. Make sure app version is correct in the XCode Project settings 2. Add a version number in sqlite file so that it can be read later

让模拟未来的更新!
1.应用的新版本被下载到设备
2.应用程序读取一个SQLite表/场以前存储的版本号
3.应用程序知道应用程序数据发生了变化,因此需要更新SQLite和也
要保留用户数据(在应用程序的最爱放;注意)。
4.架构没有改变,因此开始新的应用数据插入到一些表。
5.不触及用户数据表
6.更新的SQLite数据库的版本号。

Lets simulate the next update! 1. New version of the app is downloaded to the device 2. The app reads the version number stored earlier in a sqlite table/field 3. App knows that application data has changed so it needs to update the sqlite and also it wants to retain the user data (in app favorites & Notes). 4. Schema has not changed so it starts to insert the new application data into some tables. 5. It does not touch the user data tables 6. It updates the version number of the sqlite db.

我错过了的东西会回来咬我,当是时候更新?

Have I missed something that will come back and bite me when it is time for update?

推荐答案

所以,当你开发使用的核心数据,你开始定义核心数据模型的应用程序。每个模型都有其自己的版本。在开始创建模型的第一和唯一的版本。你可以找到所有需要的,详细的,在<一个信息href=\"http://developer.apple.com/library/ios/#documentation/cocoa/conceptual/CoreDataVersioning/Introduction/Introduction.html\"相对=nofollow>官方苹果的核心数据模型版本和数据迁移编程指南

So, when you develop an application that uses Core Data you start defining a Core Data Model. Each model will have its own version. You start creating the first and unique version of your model. You can find all the required, detailed, info at the official Apple Core Data Model Versioning and Data Migration Programming Guide

您不应通过在数据库本身设置的自定义字段处理数据库的版本,使用的模型版本,而不是通过你的X code项目。

You should not handle database versioning through custom fields set in the database itself, use model versions instead via your Xcode project.

在更新应用程序,如果你不改变,你不必担心什么型号的版本,因为该数据库尚未触及。不改变模型中的每个新的更新将不需要从你的努力。

When updating the application, if you do not change the model version you do not have to worry about anything, since the database hasn't been touched. Every new update that do not change the model will require no effort from you.

如果您需要更新您的模式,为未来的更新,你必须这样做:

If you need to update your model for the next update you have to do this:


  1. 创建一个新的模型版本

  2. 设置新的模型版本为当前版本

  3. 根据您的需要修改模型

下面到了有趣的部分。您的应用程序将处理两种不同方式的模型之间的迁移:硬盘的方式简单的方法以及

Here comes the interesting part. Your application will handle the migration between the models in two different ways: the simple way and the hard way.

随着苹果公司的约<一个官方文件href=\"http://developer.apple.com/library/ios/#documentation/cocoa/conceptual/CoreDataVersioning/Articles/vmLightweight.html\"相对=nofollow>核心数据模型版本和数据迁移的,如果你的模型已经略有改变,您可以要求应用程序执行自动轻量级迁移。这一步将现有数据库更新到新版本,如果满足了这些要求:

Following Apple's official documentation about Core Data Model Versioning and Data Migration, if your model has been slightly changed you can ask the application to perform an automatic lightweight migration. This step will update the existing database to the new version if these requirements are met:


  1. 简单增加一个新的属性

  2. 非可选属性成为可选

  3. 可选属性成为非可选,以及定义了默认值

轻型迁移过程将处理相应的必要的步骤从一个模型版本迁移到另一个,如果可能的话

The lightweight migration process will handle the appropriate required step to migrate from one model version to another, if possible

如果您不能执行自动迁移轻巧您必须手动定义的步骤更新
该模型版本的新的,使用<一个href=\"http://developer.apple.com/library/ios/#documentation/cocoa/conceptual/CoreDataVersioning/Articles/vmMappingOverview.html\"相对=nofollow>映射模型对象。这些对象将定义哪些应用程序做从模型版本迁移的 X 的模型版本的

If you can't perform an automatic lightweight migration you will have to manually define the step to update the model versions to the new one, using Mapping Model Objects. These objects will define what the application has to do to migrate from model version x to model version y.

这篇关于对应用程序更新iPhone数据迁移的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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