Save items from userdefault are not deleted even-though deleting the macOS app.

I have recently started working macOS app from iOS background. In iOS when we delete the app, all app related items also gets removed/cleared. e.g UserDefault. But it looks same is not happening incase of macOS app. The userdefault data is still there even though delete the app. Because if Installed the app after remove, Istill see old values saved in userdefault.

Answered by ssmith_c in 729226022

you are correct. The behavior might be different for sandboxed apps (I don't know, I don't write or maintain any). But why is this a problem for you? During testing, you should delete any old preferences or user data, to simulate the first-install scenario. Users may install your app, try it out, delete it and then re-install it years later. During that time, your preferences may have changed, and you have to account for that.

If you want every install for end users to be like the first install, you can use an installer rather than drag-and-drop. The installer script can delete any lingering preferences before installation.

You might also be able compare the 'date added' of your app to a timestamp you write into your preferences at first launch. If your app is now in /Applications, and was put there after the timestamp in your preferences, it has been run before (from somewhere), and you may want to clear the preferences to first-run default values. I believe the 'date added' attribute is only readable by parsing the result of a Spotlight query.

Accepted Answer

you are correct. The behavior might be different for sandboxed apps (I don't know, I don't write or maintain any). But why is this a problem for you? During testing, you should delete any old preferences or user data, to simulate the first-install scenario. Users may install your app, try it out, delete it and then re-install it years later. During that time, your preferences may have changed, and you have to account for that.

If you want every install for end users to be like the first install, you can use an installer rather than drag-and-drop. The installer script can delete any lingering preferences before installation.

You might also be able compare the 'date added' of your app to a timestamp you write into your preferences at first launch. If your app is now in /Applications, and was put there after the timestamp in your preferences, it has been run before (from somewhere), and you may want to clear the preferences to first-run default values. I believe the 'date added' attribute is only readable by parsing the result of a Spotlight query.

Save items from userdefault are not deleted even-though deleting the macOS app.
 
 
Q