应用程序更新的 iOS 方法 [英] iOS method on app update

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

问题描述

您好,我想知道在更新应用程序时是否有任何方法可以调用,类似于 androids onUpgrade().我在我的应用中使用了 SQLite 数据库,并且新版本中的架构发生了很大变化.

Hi I'm wondering if there is any method that is called when an app is updated similar to androids onUpgrade(). I'm using a SQLite database in my app and the schema has changed a lot in the new version.

如果旧版本在手机上,而我通过 Xcode 运行新版本.它不会工作,因为旧表不对应.该应用程序同步到服务器,所以我不担心用户数据.所以我可以在更新时删除所有表.

If the old version is on the phone and I run the new version through Xcode. It will not work as the old tables do not correspond. The app syncs to the server so I am not worried about the users data. So I could drop all the tables on update.

推荐答案

没有指示升级的 API.您需要自己确定这一点.有很多可能的方法.

There is no API to indicate an upgrade. You need to determine this yourself. There are many possible approaches.

我在基于 sqlite 的应用程序中所做的是在数据库中有一个元数据表.这包含架构版本号.我根据我在代码中输入的硬编码版本号进行检查.如果它们不同,那么我知道需要更新数据库.我在我的应用程序中提供了 sql 脚本,可以将任何先前的架构版本更新为当前版本.我只是运行与数据库中显示的版本匹配的脚本.

What I do in my sqlite-based app is I have a meta-data table in the database. This contains a schema version number. I check this against a hardcoded version number I put in the code. If they are different then I know the database needs to be updated. I provide sql scripts in my app that can update any prior schema version to the current version. I simply run the script that matches the version shown in the database.

这种方法允许我处理一段时间没有升级的用户,并且架构可能需要经过多次修订.

This approach allows me to deal with users that haven't upgraded in a while and the schema may need to go through multiple revisions.

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

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