Resolution:
To resolve this, I added logic to clear the Keychain when the app is put in for the primary time after being reinstalled. Right here’s the up to date AppDelegate.swift
file:
import Flutter
import UIKit
import Safety
@major
@objc class AppDelegate: FlutterAppDelegate {
func clearKeychainIfReinstalled() {
let defaults = UserDefaults.commonplace
let alreadyInstalled = defaults.bool(forKey: "has_installed")
if !alreadyInstalled {
clearKeychain()
defaults.set(true, forKey: "has_installed")
defaults.synchronize()
}
}
func clearKeychain() {
let secItemClasses = [
kSecClassGenericPassword,
kSecClassInternetPassword,
kSecClassCertificate,
kSecClassKey,
kSecClassIdentity
]
for itemClass in secItemClasses {
let question = [kSecClass: itemClass]
SecItemDelete(question as CFDictionary)
}
}
override func software(
_ software: UIApplication,
didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?
) -> Bool {
clearKeychainIfReinstalled()
GeneratedPluginRegistrant.register(with: self)
return tremendous.software(software, didFinishLaunchingWithOptions: launchOptions)
}
}
Clarification:
- Persistent Set up Examine: I used
UserDefaults
to test if the app has been beforehand put in. - Clear Keychain: If the app is being put in for the primary time after a reinstall, the
clearKeychain
operate known as, which deletes all Keychain gadgets. - Keychain Courses: The
clearKeychain
operate iterates over varied Keychain courses (kSecClassGenericPassword
,kSecClassInternetPassword
, and so on.) and removes all saved gadgets.
End result:
This ensures that delicate information is cleared upon reinstallation, and the app begins contemporary, taking the person to the login display screen as a substitute of instantly navigating to the house display screen.