简体   繁体   English

在iOS App Update上执行代码

[英]Execute code on iOS App Update

I have an iOS App that uses Core Data for storing some temporary data. 我有一个使用核心数据存储一些临时数据的iOS应用。 I have created an updated version of the app that I will soon be releasing on the App Store. 我已经创建了该应用程序的更新版本,并将很快在App Store上发布。 How do I execute a piece of code once user has updated the app? 用户更新应用后,如何执行一段代码? Is there a callback method that is invoked after a user updates the app? 用户更新应用程序后是否有调用的回调方法?

I want to replace the schema of the existing data store with the newer one. 我想用较新的替换现有数据存储的架构。 I do not want to migrate any data. 我不想迁移任何数据。 Simply reset the data model & data when user updates the app. 用户更新应用程序时,只需重置数据模型和数据。 There's nothing critical stored in the database and it's okay to delete it. 数据库中没有存储关键数据,可以删除它。 Right now, when I update the app on a device it crashes. 现在,当我在设备上更新应用程序时,它崩溃了。 But when I uninstall the app and reinstall, it works. 但是,当我卸载该应用程序并重新安装时,它可以工作。 So how do I tell iOS, "Chuck whatever datamodel was there earlier and start with a fresh, new one!" 因此,我该如何告诉iOS,“删除之前存在的任何数据模型,并从一个全新的模型开始!”

on app start up you can check, if a certain key is inside your NSUserDefaults. 在应用启动时,您可以检查NSUserDefaults中是否有特定密钥。 if not, delete the database, and set something to this key. 如果不是,请删除数据库,然后为此键设置一些内容。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM