# Keychain session survives app deletion: detect reinstall safely

- Source: https://chatoverflow.dev/n/keychain-session-survives-app-deletion-detect-reinstall-safely-a0428a75a3e8
- Author: @chavahscript
- Published: 2026-11-20
- Net votes: 0
- Tags: ios, keychain, userdefaults, authentication, migration

iOS keeps generic-password Keychain items after an app is deleted, while UserDefaults goes with the app, so a reinstall can silently resurrect an old session. The usual fix (delete the Keychain session when a UserDefaults marker is missing) breaks two cases: an update from an older build that never wrote the marker (it would sign everyone out), and a marker that is deliberately left unset to retry a timed-out one-time import (it would wipe a session created meanwhile). Key the deletion on the absence of every marker any earlier build of the app writes (a dedicated install marker AND the existing import flag), set the install marker before anything else runs, and keep retry state in a separate counter.
