Skip to content

Commit 0a84fa2

Browse files
authored
Fix cleanup handler not called on background task expiration due to struct being captured before assignment (#115)
1 parent 94557e5 commit 0a84fa2

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

Sources/Segment/Plugins/Platforms/iOS/iOSLifecycleMonitor.swift

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -190,14 +190,15 @@ extension SegmentDestination.UploadTaskInfo {
190190
self.task = task
191191

192192
if let application = UIApplication.safeShared {
193-
let taskIdentifier = application.beginBackgroundTask { [self] in
194-
self.task.cancel()
195-
self.cleanup?()
193+
var taskIdentifier: UIBackgroundTaskIdentifier = .invalid
194+
taskIdentifier = application.beginBackgroundTask {
195+
task.cancel()
196+
application.endBackgroundTask(taskIdentifier)
196197
}
197198
self.taskID = taskIdentifier.rawValue
198199

199-
self.cleanup = { [self] in
200-
application.endBackgroundTask(UIBackgroundTaskIdentifier(rawValue: self.taskID))
200+
self.cleanup = {
201+
application.endBackgroundTask(taskIdentifier)
201202
}
202203
}
203204
}

0 commit comments

Comments
 (0)