Skip to content

Commit

Permalink
fixed crashes with ios offline manager (#724)
Browse files Browse the repository at this point in the history
* fixed crashes with ios offline manager

* removed redundant call to releaseDownloader
  • Loading branch information
felix-ht authored Oct 26, 2021
1 parent 5921ef7 commit 899975f
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
4 changes: 4 additions & 0 deletions ios/Classes/OfflineManagerUtils.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
4 changes: 1 addition & 3 deletions ios/Classes/OfflinePackDownloadManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,6 @@ class OfflinePackDownloader {
))
if let region = OfflineRegion.fromOfflinePack(pack) {
OfflineManagerUtils.deleteRegion(result: result, id: region.id)
OfflineManagerUtils.releaseDownloader(id:region.id)
}
}

Expand All @@ -158,7 +157,6 @@ class OfflinePackDownloader {
))
if let region = OfflineRegion.fromOfflinePack(pack) {
OfflineManagerUtils.deleteRegion(result: result, id: region.id)
OfflineManagerUtils.releaseDownloader(id: region.id)
}
}

Expand Down Expand Up @@ -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(
Expand Down

0 comments on commit 899975f

Please sign in to comment.