Skip to content

Commit

Permalink
explicitly cancel BGTasks
Browse files Browse the repository at this point in the history
  • Loading branch information
Dennis Jüni committed Mar 17, 2022
1 parent 97997e5 commit bd10796
Showing 1 changed file with 23 additions and 1 deletion.
24 changes: 23 additions & 1 deletion Sources/DP3TSDK/Background/DP3TBackgroundTaskManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,15 @@ class DP3TBackgroundTaskManager {

private weak var tracer: Tracer!

var shouldReschedule: Bool = true
var shouldReschedule: Bool = true {
didSet {
if shouldReschedule == false {
if #available(iOS 13.0, *) {
cancelScheduledTask()
}
}
}
}

init(handler: DP3TBackgroundHandler?,
keyProvider: DiagnosisKeysProvider,
Expand Down Expand Up @@ -87,6 +95,11 @@ class DP3TBackgroundTaskManager {

private func handleiOS12BackgroundLaunch() {
logger.trace()

if !shouldReschedule {
return
}

let queue = OperationQueue()

if let handler = handler {
Expand All @@ -110,6 +123,10 @@ class DP3TBackgroundTaskManager {
private func handleExposureNotificationBackgroundTask(_ task: BGTask) {
logger.trace()
scheduleBackgroundTasks()

if !shouldReschedule {
return
}

let queue = OperationQueue()

Expand Down Expand Up @@ -213,4 +230,9 @@ class DP3TBackgroundTaskManager {
logger.error("Exposure notification task schedule failed error: %{public}@", error.localizedDescription)
}
}

@available(iOS 13.0, *)
func cancelScheduledTask() {
BGTaskScheduler.shared.cancelAllTaskRequests()
}
}

0 comments on commit bd10796

Please sign in to comment.