diff --git a/iphone/Maps/Core/BackgroundFetchScheduler/BackgroundFetchTask/BackgroundFetchTask.swift b/iphone/Maps/Core/BackgroundFetchScheduler/BackgroundFetchTask/BackgroundFetchTask.swift index 616004dd5d..b316f3a9fe 100644 --- a/iphone/Maps/Core/BackgroundFetchScheduler/BackgroundFetchTask/BackgroundFetchTask.swift +++ b/iphone/Maps/Core/BackgroundFetchScheduler/BackgroundFetchTask/BackgroundFetchTask.swift @@ -8,18 +8,24 @@ var completionHandler: BackgroundFetchScheduler.FetchResultHandler! func start() { - backgroundTaskIdentifier = UIApplication.shared.beginBackgroundTask(expirationHandler: { - self.finish(.failed) - }) - if backgroundTaskIdentifier != UIBackgroundTaskInvalid { - queue.async(execute: block) + DispatchQueue.main.async { + self.backgroundTaskIdentifier = UIApplication.shared.beginBackgroundTask(expirationHandler: { + self.finish(.failed) + }) + if self.backgroundTaskIdentifier != UIBackgroundTaskInvalid { + self.queue.async(execute: self.block) + } } } func finish(_ result: UIBackgroundFetchResult) { guard backgroundTaskIdentifier != UIBackgroundTaskInvalid else { return } - UIApplication.shared.endBackgroundTask(backgroundTaskIdentifier) - backgroundTaskIdentifier = UIBackgroundTaskInvalid - completionHandler(result) + DispatchQueue.main.async { + UIApplication.shared.endBackgroundTask(self.backgroundTaskIdentifier) + self.backgroundTaskIdentifier = UIBackgroundTaskInvalid + self.queue.async { + self.completionHandler(result) + } + } } }