[英]Is there a way to remove all the data/caches when upgrading app from AppStore
Small percentage of my user get ugly bug related to WKWebView when updating to the latest version of my app from AppStore. 从AppStore更新到我的应用程序的最新版本时,一小部分用户会收到与WKWebView相关的丑陋错误。 The bug goes away when the app is removed and installed all over again.
重新删除并重新安装该应用程序后,该错误消失。 Is there a way to remove old data/caches during the upgrade?
有没有办法在升级过程中删除旧数据/缓存?
All the code is removed when you update an app. 更新应用程序时,所有代码都将被删除。 If your app changes how it uses for example data that isn't removed, such as NSUserDefaults you have to add logic in your code to handle "old" data being present.
如果您的应用更改了使用方式,例如未删除的数据(例如NSUserDefaults),则必须在代码中添加逻辑以处理存在的“旧”数据。
Not sure if this will work but here is two possible approaches: 不知道这是否行得通,但这是两种可能的方法:
When your app loads up, in AppDelegate check for saved data inside the didLaunchWithOptions()
: 当您的应用加载时,在AppDelegate中检查
didLaunchWithOptions()
保存的数据:
func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
if let data = userDefaults.valueForKey("<yourKey>") {
userDefaults.removeObjectForKey("<yourKey>")
}
return true
}
You'll have to insert the keys used in your application for saving stuff instead of <yourKey>
, of course. 当然,您必须插入应用程序中用于保存内容的键,而不是
<yourKey>
。
You could also try the following code, that will erase all the contents of NSUserDefaults, which will make the key unnecessary: 您还可以尝试以下代码,该代码将擦除NSUserDefaults的所有内容,这将使密钥变得不必要:
NSUserDefaults.standardUserDefaults().removePersistentDomainForName(NSBundle.mainBundle().bundleIdentifier!)
Hope that helps :) 希望有帮助:)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.