Skip to content

Commit

Permalink
Automatically purges LoggedErrors older than one month
Browse files Browse the repository at this point in the history
Occurs whenever app enters background.
  • Loading branch information
rileytestut committed Sep 9, 2022
1 parent 6ec47bb commit b8e1360
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
13 changes: 13 additions & 0 deletions AltStore/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
13 changes: 13 additions & 0 deletions AltStore/SceneDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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>)
Expand Down

0 comments on commit b8e1360

Please sign in to comment.