Skip to content

Longer downloads fail silently when app is backgrounded on iOS #353

@bikubi

Description

@bikubi

Bug Report

Problem

Reproduce:

  • Start a download that runs approx. longer than 30s.
  • Background the app (i.e. home button, open other app)
  • Be on battery (no cable) for quicker fails. Also iPhones fail quicker than iPads. YMMV.

What is expected to happen?

  • The download continues until it's done

What does actually happen?

  • The download fails
  • The file is not created
  • neither success nor error handlers are called

Information

  • This seems to be a common issue for background tasks on cordova. Hence the existence of the background mode plugin, which doesn't work any more with modern OSes. See also Android doze.
  • I thought it might not apply because i see several references to backgroundTaskID etc. in the code, which the general docs about background execution talk about. But I'm too unfamiliar with iOS dev to really tell.
  • I thought the "background fetch" capability would solve this, but nope. Might need a specific implementation to work.
  • This is somewhat related to There's any way to resume downloads? #213, essentially a duplicate of the issue described in this comment, but its own issue -- resumable downloads could mitigate / work around, but not solve the core issue.
  • Seems not to affect Android, but I might have to test harder (longer downloads)
  • I will give https://github.com/sgrebnov/cordova-plugin-background-download a try, but I am not getting my hopes up
  • At the very least, the error callback should fire.
  • For now I guess I'll have to add a hint: "Please don't close the app while download is running"... (or remember that I had started a download, an then onforeground check if it is still running, check if the file is there... oof, heuristic headaches)

Environment, Platform, Device

I think only iOS, Android needs more testing.

Version information

  • cordova 11.0.0
  • cordova-ios 6.2.0
  • current dev version of this plugin 7ba6fa3 (but also 5ed73ae)
  • cordova-plugin-file 7.0.0 (but also 5.0.0)
  • Xcode 13.1
  • iOS 15.4.1, 16(.1 iirc), 12.3.1 (I think. It looks like that one has just trained itself for longer exec times, sigh)

Checklist

  • I searched for existing GitHub issues
  • I updated all Cordova tooling to most recent version
  • I included all the necessary information above

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions