Problem:
While developing my Flutter app for iOS, I encountered an issue where, if a user uninstalls the app while logged in, upon reinstalling, the app would skip the login screen and directly navigate to the home screen. This was happening because sensitive data like the access token was stored in the Keychain, which persists even after the app is uninstalled.
Here’s the AppDelegate.swift
file:
import Flutter
import UIKit
@main
@objc class AppDelegate: FlutterAppDelegate {
override func application(
_ application: UIApplication,
didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?
) -> Bool {
GeneratedPluginRegistrant.register(with: self)
return super.application(application, didFinishLaunchingWithOptions: launchOptions)
}
}
2
Answers
Solution: To resolve this, I added logic to clear the Keychain when the app is installed for the first time after being reinstalled. Here’s the updated
AppDelegate.swift
file:Explanation:
UserDefaults
to check if the app has been previously installed.clearKeychain
function is called, which deletes all Keychain items.clearKeychain
function iterates over various Keychain classes (kSecClassGenericPassword
,kSecClassInternetPassword
, etc.) and removes all stored items.Outcome: This ensures that sensitive data is cleared upon reinstallation, and the app starts fresh, taking the user to the login screen instead of directly navigating to the home screen.
check the credentails and app info remove the local storage and cached some time cached are saved then this issue are persisted but ios build uninstalled not saved the credentails but please check the double crosss checking