Automatically purges LoggedErrors older than one month

Occurs whenever app enters background.
This commit is contained in:
Riley Testut
2022-09-09 17:47:49 -05:00
parent 6ec47bbe0c
commit b8e136005a
2 changed files with 26 additions and 0 deletions

View File

@@ -98,7 +98,20 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
func applicationDidEnterBackground(_ application: UIApplication)
{
// Make sure to update SceneDelegate.sceneDidEnterBackground() as well.
ServerManager.shared.stopDiscovering()
guard let oneMonthAgo = Calendar.current.date(byAdding: .month, value: -1, to: Date()) else { return }
let midnightOneMonthAgo = Calendar.current.startOfDay(for: oneMonthAgo)
DatabaseManager.shared.purgeLoggedErrors(before: midnightOneMonthAgo) { result in
switch result
{
case .success: break
case .failure(let error): print("[ALTLog] Failed to purge logged errors before \(midnightOneMonthAgo).", error)
}
}
}
func applicationWillEnterForeground(_ application: UIApplication)

View File

@@ -52,7 +52,20 @@ class SceneDelegate: UIResponder, UIWindowSceneDelegate
guard UIApplication.shared.applicationState == .background else { return }
// Make sure to update AppDelegate.applicationDidEnterBackground() as well.
ServerManager.shared.stopDiscovering()
guard let oneMonthAgo = Calendar.current.date(byAdding: .month, value: -1, to: Date()) else { return }
let midnightOneMonthAgo = Calendar.current.startOfDay(for: oneMonthAgo)
DatabaseManager.shared.purgeLoggedErrors(before: midnightOneMonthAgo) { result in
switch result
{
case .success: break
case .failure(let error): print("[ALTLog] Failed to purge logged errors before \(midnightOneMonthAgo).", error)
}
}
}
func scene(_ scene: UIScene, openURLContexts URLContexts: Set<UIOpenURLContext>)