简体   繁体   English

永久数据仍然导致应用程序崩溃,即使在应用程序更新后

[英]Persistent data still causing application to crash even after app update

I am using Firebase for my data and using persistence to allow offline viewing of that data. 我将Firebase用于我的数据,并使用持久性来允许离线查看该数据。 My app is still in beta so I am still finding bugs that crash the app and fixing them but when I push a new update the app still crashes until I delete the app and reinstall a fresh version. 我的应用仍处于测试阶段,因此我仍然发现使该应用崩溃的错误并进行修复,但是当我推送新更新时,该应用仍然会崩溃,直到删除该应用并重新安装新版本为止。 For example, I have a list of users. 例如,我有一个用户列表。 If a user signs up for the app and it gets entered incorrectly in the database, the rest of the app works fine but just the users menu where the user can see all of the users crashes. 如果用户注册了该应用程序,但该应用程序在数据库中的输入错误,则该应用程序的其余部分都可以正常工作,但只有用户菜单,用户可以在其中看到所有用户崩溃。 So I fix the error and push out a new version on TestFlight but that users view still crashes even though I fixed the issue. 因此,我更正了该错误,并在TestFlight上推出了一个新版本,但是即使我已解决了该问题,该用户视图仍然崩溃。 It's not until I delete the app and reinstall that it works. 直到我删除该应用程序并重新安装它后,它才能起作用。

I know this is due to my having persistence turned on but is there a way to programmatically clear what is in memory only when a new version of the app is installed? 我知道这是由于我已启用持久性功能,但是只有在安装了新版本的应用程序之后,有没有办法以编程方式清除内存中的内容? I don't want to have to tell all of my testers to delete and reinstall every time a bug comes up if I don't have to. 如果不需要,我不需要告诉所有测试人员每次出现错误时都删除并重新安装。

It sounds like you changed the database/content structure in the new version. 听起来好像您在新版本中更改了数据库/内容结构。 So read/write to the old (persisted) database/content failed. 因此,读取/写入旧(持久)数据库/内容失败。 Normally you have to define migration rules that convert your database/content from an old version to the new one, so you can use it after the update without problems. 通常,您必须定义迁移规则,以将数据库/内容从旧版本转换为新版本,因此您可以在更新后使用它而不会出现问题。 I do not know Firebase, so I can't help you with it. 我不了解Firebase,因此无法为您提供帮助。

Another alternative is to remove the persisted data whenever you have an incompatible new version and start with a cleanup directly after the update. 另一种选择是,只要您有不兼容的新版本,就删除持久化的数据,并在更新后立即进行清理。 Assuming that the already launched app has the version 1.0.0 you can do something like that early in your app flow: 假设已经启动的应用程序的版本为1.0.0,则可以在应用程序流程的早期执行类似的操作:

NSString *lastKnownVersion = [[NSUserDefaults standardUserDefaults] stringForKey:@"LastKnownAppVersion"];
NSString *currentVersion = [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleVersion"]
if (!lastKnownVersion || [currentVersion compare:newVersion options:NSNumericSearch]==NSOrderedAscending) {
    if (!lastKnownVersion) {
        // first start after update from version 1.0.0 (or lower) to a larger version
        // cleanup code here
    } else if ([lastKnownVersion compare:@"2.0.0" options:NSNumericSearch]==NSOrderedAscending) {
        // first start after update from version 1.0.1 up to 2.0.0 to a larger version
        // cleanup code here
    } // ... add more versions that need a legacy handling
    [[NSUserDefaults standardUserDefaults] setObject:currentVersion forKey:@"LastKnownAppVersion"];
    [[NSUserDefaults standardUserDefaults] synchronize];
}

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

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