781flyingdutchman / background_downloader

Flutter plugin for file downloads and uploads
Other
162 stars 76 forks source link

Download Cancels Instead of Pausing on iOS When Using Background Downloader in Flutter #389

Closed KevinShingala closed 1 month ago

KevinShingala commented 1 month ago

When attempting to pause a download using a background downloader in Flutter on iOS, the download is unexpectedly canceled rather than paused. This behavior is inconsistent with Android, where the pause and resume functionalities work as expected. The issue seems to occur specifically on iOS, where pausing a download results in the download being completely terminated instead of being suspended for resumption later.

Steps to Reproduce:

Set up a background download task in Flutter for both Android and iOS. Start a download on an iOS device. Attempt to pause the download. Observe that the download is canceled rather than paused. Expected Behavior: On iOS, pausing a download should temporarily suspend the download task, allowing it to be resumed from the point it was paused.

Actual Behavior: Pausing the download on iOS results in the download being canceled, losing all progress, and preventing the ability to resume the task.

781flyingdutchman commented 1 month ago

On iOS the operating system determines when a task can be resumed when it is paused. If it cannot be resumed, then it is effectively canceled when you try to pause it. The code is like this:

let resumeData = await urlSessionTask.cancelByProducingResumeData()

If resumeData is nil then the OS was unable to produce the resumeData needed to resume the task - no reason is given.

On Android, the plugin (my code) determines whether a task can be resumed (based on whether the server accepts ranges, the temp file can be preserved, etc).

I have not heard the issue you raise before, but I can only assume that iOS has a reason for determining the task cannot be resumed that does not apply in the Android case. Unfortunately there is nothing I can do to change how iOS determines this.