added live logic for checking/saving app version to clear cache
Signed-off-by: Matt Bruce <mbrucedogs@gmail.com>
This commit is contained in:
parent
c2768a4864
commit
eeefcf19b7
@ -11,6 +11,25 @@ class SceneDelegate: UIResponder, UIWindowSceneDelegate {
|
|||||||
|
|
||||||
var window: UIWindow?
|
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) {
|
func scene(_ scene: UIScene, willConnectTo session: UISceneSession, options connectionOptions: UIScene.ConnectionOptions) {
|
||||||
|
|
||||||
@ -25,13 +44,19 @@ class SceneDelegate: UIResponder, UIWindowSceneDelegate {
|
|||||||
let navigationController = UINavigationController(rootViewController: employeeListVC)
|
let navigationController = UINavigationController(rootViewController: employeeListVC)
|
||||||
window.rootViewController = navigationController
|
window.rootViewController = navigationController
|
||||||
|
|
||||||
let appVersion = 1.5// get app version
|
// get app version
|
||||||
let currentVersion = 1.0 //cached 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()
|
EmployeeCacheService.shared.clear()
|
||||||
|
// save the current app version for next run
|
||||||
|
saveAppVersion(currentAppVersion)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Set the window to the scene
|
// Set the window to the scene
|
||||||
self.window = window
|
self.window = window
|
||||||
window.makeKeyAndVisible()
|
window.makeKeyAndVisible()
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user