Are UserDefaults wiped when deleting an app on iOS 13/14?

Viewed 1172

When I use plain UserDefaults without any other frameworks and not with NSUbiquitousKeyValueStore, will the UserDefaults be kept in iCloud after deletion of the app from the phone and restored from iCloud upon reinstallation of that app?

I have read in the docs that generally UserDefaults are included in the (iCloud) backup. So if a user installs the app, the app then stores some UserDefaults, the user makes an iCloud backup and then restores the phone from that backup, the UserDefaults should be there again.

But what if the user purposefully deletes my app from their phone and then reinstalls it from the store, will the UserDefaults still be there (restored from iCloud) or are they wiped out with the app deletion and not coming back with the reinstallation?

Would the user have to additionally delete the iCloud data of my app from the iCloud settings app to get rid of the UserDefaults or does it come with deleting the app (not moving to App Library)?

I basically want to start from zero after a user removes the app from the phone.

Is this different between iOS 13 and iOS 14?

1 Answers

When an app is deleted from the device all local data associated with the app will be deleted too. This includes NSUserDefaults. However any data stored at an online service won't. For example, iCloud. The app will just fetch the data again if requested to do so by the user / developer.

I had a problem before where UserDefaults are getting deleted when the user delete my application. So just for educational purposes, if you don't want your data to be lost, and you don't want to store your data online, consider using Keychain.

For more information you can find it here: Keychain

Related