UserDefaults not cleared after Uninstall

Hi, We assume that when uninstalling an application, the UserDefaults are deleted.

Starting iOS16 we encounter complaints from clients that this is not the case. We have succeeded in debugging a device where this occurred (UserDefaults were not deleted after uninstall+install), but have not succeeded in recreating this issue on another device.

We assume this issue has a connection to iCloud sync, although UserDefaults iCloud synching should be specifically set up (using NSUbiquitousKeyValueStore) which we have NOT set. Or maybe it has to do with Family Sharing.

We are initializing the UserDefaults with suiteName for usage in widgets, but assume this has not connection to the bug.

Answered by yasmin777 in 737268022

Save a parameter isNotFirstInstall in user defaults.standard. Set it to true after you do your 'first install' stuff. If you need this value in the app groups other apps, the main app should make a copy of this value under a different name in the app groups user defaults. When the main app is uninstalled and then installed again, isNotFirstInstall will be nil and then the main app can delete the values in the app groups user defaults since you know all the keys. Let me know if this helps.

Hello, I have a same problem. My iPhone os version is iOS 16.0.3, our app show a onboarding screen using userdefaults when user install the app. but my device didn't show that screen. I debugging my device, the problem was userdefaults not cleared after uninstall. Even If I login into the app, and uninstall and install again, then the login state is keep. It's very weird....

But there are some weird point there, only our app is strange in my device, other app works nomarlly. (but I don't know other app mechanism...)

I think it's iOS bug. but it's not sure.

My device has family sharing. so I will remove family sharing to test this.


I remove family sharing and uninstall the app. but the problem still appeared.. I'm so annoying.

I tested userdefaults. So I saved data in appgroups, and that data not cleared after uninstall. but other data saved in userdefaults.standard, cleared after uninstall. What is the problem???

I uninstall every app in app groups, but the error still appeared. How can I do.. please help me.

Accepted Answer

Save a parameter isNotFirstInstall in user defaults.standard. Set it to true after you do your 'first install' stuff. If you need this value in the app groups other apps, the main app should make a copy of this value under a different name in the app groups user defaults. When the main app is uninstalled and then installed again, isNotFirstInstall will be nil and then the main app can delete the values in the app groups user defaults since you know all the keys. Let me know if this helps.

The accepted answer is a workaround that shouldn't be needed, if the bug is fixed in the first place.

@yasmin777 any update on your bug report?

Still same issue here. Data stored in group UserDefaults is not cleared.

The same happens on tvOS 17.0. It looks like it could be caused by OS not being fast enough when deleting user data. Perhaps OS schedules the data removal and it takes time for it to take effect. I had similar problem, but removing the app, installing again and deleting again solved the problem. If it is necessary to remove app and do fresh install, it is better to suggest to users removing the app waiting for a minute or rebooting device and then do the install.

UserDefaults not cleared after Uninstall
 
 
Q