Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Loop/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ final class AppDelegate: UIResponder, UIApplicationDelegate {
setenv("CFNETWORK_DIAGNOSTICS", "3", 1)

self.launchOptions = launchOptions
loopAppManager.registerBackgroundTasks()

return true
}
Expand Down
14 changes: 8 additions & 6 deletions Loop/Managers/LoopAppManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -130,12 +130,16 @@ class LoopAppManager: NSObject {

func registerBackgroundTasks() {
let taskIdentifier = CriticalEventLogExportManager.historicalExportBackgroundTaskIdentifier
let registered = BGTaskScheduler.shared.register(forTaskWithIdentifier: taskIdentifier, using: nil) { task in
guard let criticalEventLogExportManager = self.criticalEventLogExportManager else {
self.log.error("Critical event log export launch handler called before initialization complete!")
let registered = BGTaskScheduler.shared.register(forTaskWithIdentifier: taskIdentifier, using: .main) { task in
guard let criticalEventLogExportManager = self.criticalEventLogExportManager,
let processingTask = task as? BGProcessingTask else {
self.log.error("Cannot start critical event log export: export manager or processing task unavailable")
task.setTaskCompleted(success: false)
return
}
criticalEventLogExportManager.handleCriticalEventLogHistoricalExportBackgroundTask(task as! BGProcessingTask)
DispatchQueue.global(qos: .background).async {
criticalEventLogExportManager.handleCriticalEventLogHistoricalExportBackgroundTask(processingTask)
}
}
if registered {
log.debug("Critical event log export background task registered")
Expand All @@ -149,8 +153,6 @@ class LoopAppManager: NSObject {

UNUserNotificationCenter.current().delegate = self

registerBackgroundTasks()

Task {
await resumeLaunch()
}
Expand Down