简体   繁体   中英

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. 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.

Not sure if this will work but here is two possible approaches:

1.

When your app loads up, in AppDelegate check for saved data inside the 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.

2.

You could also try the following code, that will erase all the contents of NSUserDefaults, which will make the key unnecessary:

NSUserDefaults.standardUserDefaults().removePersistentDomainForName(NSBundle.ma‌​inBundle().bundleIdentifier!)

Hope that helps :)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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