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.

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

Add a Comment

Accepted Reply

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.

Replies

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.

  • Can you try uninstall + install twice after removing family sharing and also restart the phone? Can you remove iCloud sync also and try uninstall + install twice? I reported a bug. I will post the answer when I receive it

  • I still don't know when this bug occurs, but I have a phone in which this occurs and I fixed it by changing this flag to look at the existence of a folder instead of a flag in user defaults (I create/delete the folder according to the flag). Annoying indeed... If you want I'll post the code.

Add a Comment

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.

  • I moved the flag from UserDefaults to existence of a directory that I create on first launch. If it's not important to preserve the existing flag (for example, you don't care that everybody will see the onboarding again) then you can just move to this mechanism. If it is important then you need to "migrate" the current setting: if flag exists then create the directory and delete the flag. In this way the first uninstall + install will not work but the second will

  • I opened a bug in the feedback assistant. I'm waiting for a replay

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

Add a Comment

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.