Reputation: 89
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)
}
}
Upvotes: 3
Views: 62
Reputation: 89
I ran into this issue where the app kept old Keychain data after reinstalling. Here's how I fixed it by clearing the Keychain on first launch after reinstall:
import Flutter
import UIKit
import Security
@main
@objc class AppDelegate: FlutterAppDelegate {
private func checkAndClearKeychainIfNeeded() {
let defaults = UserDefaults.standard
if !defaults.bool(forKey: "app_installed_flag") {
// First launch after install/reinstall
wipeKeychainData()
defaults.set(true, forKey: "app_installed_flag")
defaults.synchronize()
}
}
private func wipeKeychainData() {
let keychainItemClasses = [
kSecClassGenericPassword,
kSecClassInternetPassword,
kSecClassCertificate,
kSecClassKey,
kSecClassIdentity
]
for itemClass in keychainItemClasses {
let spec = [kSecClass: itemClass]
SecItemDelete(spec as CFDictionary)
}
}
override func application(
_ application: UIApplication,
didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?
) -> Bool {
checkAndClearKeychainIfNeeded()
GeneratedPluginRegistrant.register(with: self)
return super.application(application, didFinishLaunchingWithOptions: launchOptions)
}
}
The main issue was that the Keychain persists even after app uninstall. To fix this, I follow the following steps
This solved my login bypass issue by ensuring old tokens are cleared on reinstall. The app now properly requires login after reinstallation.
Upvotes: 3
Reputation: 1
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
Upvotes: -1