Menu

1 / 2

Downloading Files in the Background in Capacitor

DEV Community: ionic·Robin·6 days ago
#A7SjbDoO
#devtoionic#devto#dev#transfer#background
Reading 0:00
15s threshold

If your Capacitor app downloads a large file with fetch , the download dies as soon as the user switches apps for more than a few seconds. In this post, we look at why that happens, how to hand the download to the native transfer engines of Android and iOS, and what your app sees after the OS kills it or the user force-quits it.

Prerequisites

A Capacitor 8 app with Android and/or iOS platforms added.

The Capacitor File Transfer plugin . We build this plugin at Capawesome, and it is part of Capawesome Insiders , a paid subscription.

Why fetch stops

A download started with fetch , XMLHttpRequest or any other JavaScript API runs in the web view, inside your app's process. When iOS suspends that process, the download stops with it. Apple's background execution guide is clear about how fast that happens:

When your app moves to the background, the system calls your app delegate's applicationDidEnterBackground(_:) method. That method has five seconds to perform any tasks and return.…

Continue reading — create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.