kesha-antonov / react-native-background-downloader

About A library for React-Native to help you download large files on iOS and Android both in the foreground and most importantly in the background.
https://www.npmjs.com/package/@kesha-antonov/react-native-background-downloader
Other
26 stars 3 forks source link

Differences between checkForExistingDownloads and ensureDownloadsAreRunning? #13

Open felipegmg opened 1 month ago

felipegmg commented 1 month ago

Hi! Im in doubt which method i must use. In documentation, the "check" method is used as a preparation of "ensure" method, but in the same times, the documentation has said that those two methods are used to resume a download. So, my question is: Can I use only the checkForExistingDownloads to resume a download, in view of "ensure" method can only been used in iOS devices. Tks a Lot!

kesha-antonov commented 1 month ago

Hi

As you can see here:

https://github.com/kesha-antonov/react-native-background-downloader/blob/1f52afe3d4359d9c66f0216c3e89b1ae7a7a5f6e/index.ts#L95-L105

ensureDownloadsAreRunning is just wrapper around checkForExistingDownloads to get tasks and call pause & resume on them to ensure they're running. It's good to call this method when app resumed from background - in case when you have problem when downloads stuck sometimes.

So you don't need to call checkForExistingDownloads as a preparation

kesha-antonov commented 1 month ago

checkForExistingDownloads is good to use on app startup when you want to re-attach those tasks to your app logic