added live logic for checking/saving app version to clear cache

Signed-off-by: Matt Bruce <mbrucedogs@gmail.com>
This commit is contained in:
Matt Bruce 2025-02-06 15:33:40 -06:00
parent c2768a4864
commit eeefcf19b7

View File

@ -11,6 +11,25 @@ class SceneDelegate: UIResponder, UIWindowSceneDelegate {
var window: UIWindow?
let keyAppVersion = "savedAppVersion"
func getAppVersion() -> String {
if let version = Bundle.main.infoDictionary?["CFBundleShortVersionString"] as? String,
let build = Bundle.main.infoDictionary?["CFBundleVersion"] as? String {
return "\(version) (\(build))"
}
return "Unknown Version"
}
// Retrieve saved version
func getSavedAppVersion() -> String? {
return UserDefaults.standard.string(forKey: keyAppVersion)
}
func saveAppVersion(_ version: String) {
UserDefaults.standard.set(version, forKey: keyAppVersion)
UserDefaults.standard.synchronize()
}
func scene(_ scene: UIScene, willConnectTo session: UISceneSession, options connectionOptions: UIScene.ConnectionOptions) {
@ -25,13 +44,19 @@ class SceneDelegate: UIResponder, UIWindowSceneDelegate {
let navigationController = UINavigationController(rootViewController: employeeListVC)
window.rootViewController = navigationController
let appVersion = 1.5// get app version
let currentVersion = 1.0 //cached version
// get app version
let currentAppVersion = getAppVersion()
if appVersion != currentVersion {
// get app cached version
let savedAppVersion = getSavedAppVersion() ?? "none"
// check to see if there is a diff and if so clear cache
if savedAppVersion != currentAppVersion {
EmployeeCacheService.shared.clear()
// save the current app version for next run
saveAppVersion(currentAppVersion)
}
// Set the window to the scene
self.window = window
window.makeKeyAndVisible()