From 899975f9a7a5a4dbf457a081558633f7f624fb49 Mon Sep 17 00:00:00 2001 From: Felix Horvat Date: Tue, 26 Oct 2021 20:00:53 +0200 Subject: [PATCH] fixed crashes with ios offline manager (#724) * fixed crashes with ios offline manager * removed redundant call to releaseDownloader --- ios/Classes/OfflineManagerUtils.swift | 4 ++++ ios/Classes/OfflinePackDownloadManager.swift | 4 +--- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/ios/Classes/OfflineManagerUtils.swift b/ios/Classes/OfflineManagerUtils.swift index 749baf0b3..4e345dc10 100644 --- a/ios/Classes/OfflineManagerUtils.swift +++ b/ios/Classes/OfflineManagerUtils.swift @@ -70,6 +70,10 @@ class OfflineManagerUtils { } }) if let packToRemoveUnwrapped = packToRemove { + // deletion is only safe if the download is suspended + packToRemoveUnwrapped.suspend() + OfflineManagerUtils.releaseDownloader(id: id) + offlineStorage.removePack(packToRemoveUnwrapped) { error in if let error = error { result(FlutterError( diff --git a/ios/Classes/OfflinePackDownloadManager.swift b/ios/Classes/OfflinePackDownloadManager.swift index e1802ff9a..187953563 100644 --- a/ios/Classes/OfflinePackDownloadManager.swift +++ b/ios/Classes/OfflinePackDownloadManager.swift @@ -134,7 +134,6 @@ class OfflinePackDownloader { )) if let region = OfflineRegion.fromOfflinePack(pack) { OfflineManagerUtils.deleteRegion(result: result, id: region.id) - OfflineManagerUtils.releaseDownloader(id:region.id) } } @@ -158,7 +157,6 @@ class OfflinePackDownloader { )) if let region = OfflineRegion.fromOfflinePack(pack) { OfflineManagerUtils.deleteRegion(result: result, id: region.id) - OfflineManagerUtils.releaseDownloader(id: region.id) } } @@ -193,7 +191,7 @@ class OfflinePackDownloader { return false } // We can tell whether 2 packs are the same by comparing metadata we assigned earlier - return pack.context == currentlyManagedPack.context + return pack.state != .invalid && pack.context == currentlyManagedPack.context } private func calculateDownloadingProgress(