Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Download restarts from 0 after app close and open #24

Open
3 tasks done
surafelbm opened this issue Jul 12, 2024 · 8 comments
Open
3 tasks done

Download restarts from 0 after app close and open #24

surafelbm opened this issue Jul 12, 2024 · 8 comments

Comments

@surafelbm
Copy link

Is this a bug report, a feature request, or a question?

Bug report

Have you followed the required steps before opening a bug report?

(Check the step you've followed - put an x character between the square brackets ([]).)

Is the bug specific to iOS or Android? Or can it be reproduced on both platforms?

i am only testing on iOS

(Write your answer here and specify the iOS/Android versions on which you've been able to reproduce the issue.)
i am using iOS 17.0 on iPhone 15 Pro Max Simulator (also tried on device same issue)

Is the bug related to the native implementation? (NSURLSession on iOS and Fetch on Android)

(Write your answer here.)
no i haven't

Environment

(Write your answer here.)
"react-native": "0.70.6",
"react": "18.1.0",
"@kesha-antonov/react-native-background-downloader": "kesha-antonov/react-native-background-downloader",

currently downloading the package from github directly was having the same issues as this issue and saw that a fix was merged so i switch to the github version

i can confirm the issue also happens on the npm official version

Expected Behavior

(Write what you thought would happen.)
start download half way through the download i close the app clear it from recent apps and when i re-open i expect the download to not start from scratch

Actual Behavior

(Write what happened. Add logs!)
I start a download wait until it get to about 30% and i close the app and remove from recent apps, after a few minutes i open back the app the download starts back from 0% and downloads from scratch

i am calling await RNBackgroundDownloader.checkForExistingDownloads() on initial stage on App.ts and i get a list of downloads i started(in this case i started 2 downloads) two of them are returned from the function and the download starts automatically but starts from scratch i also tried calling await RNBackgroundDownloader.ensureDownloadsAreRunning() also tried only triggering one download and same issue

Steps to Reproduce

(Write your steps so that anyone can reproduce the issue in the Snack demo you provided.)

1.when download button is called i am starting two downloads at the same time with the download function
2.after download start i close the app
3.i have RNBackgroundDownloader.checkForExistingDownloads() in App.js which recognizes there is a download happening
4. but the download starts from 0

@HyopeR
Copy link
Contributor

HyopeR commented Jul 14, 2024

Hi.
I developed the pull request mentioned.
I am not sure what is not working for you.
I am trying what you said on the "example" application now and the results are as follows.

Maybe you missed something simple. After downloading the new version, "pod install".
Or some websites may not support "HTTP 206 Partial Content".
Have you tried with different files?

Android Ios
android.mp4
ios.mp4

Example application control;

You may want to check how things are done in the "example" application.
I know that the "example" application in this repository is not up to date at the moment.
Can you clone this repository and check how things are done in the "example" application?

1- git clone -b temporary https://github.com/HyopeR/react-native-background-downloader.git
2- cd react-native-background-donwloader
3- cd example
4- npm install or yarn
5- cd ios
6- pod install
7- Then test the "example" application in the ios simulator.

@surafelbm
Copy link
Author

@HyopeR , thank you so much for your reply, but i think i can see the same issue on the iOS screen recording you shared right before you close the example application i can see the download is like a quarter done on the progress bar but when you re-open it it starts from 0, am i missing something? thanks

@HyopeR
Copy link
Contributor

HyopeR commented Jul 14, 2024

I think I understand.
You are talking about starting from 0 before the first sync is completed.
Actually, this is not a start from scratch.
After the first sync is done, the downloads continue where they left off as you can see.
I don't see any functional issues. However, on the IOS platform, the checkForExistingDownloads function may be giving the wrong initial downloaded data size.

@surafelbm
Copy link
Author

Ow okay so even tho the progress on checkForExistingDownloads seems to be starting from 0 thats not actually the case?

@HyopeR
Copy link
Contributor

HyopeR commented Jul 14, 2024

Yes, I'm pretty sure it is.
I did some testing on the IOS native modules when I made the pull request.
I can confirm that ongoing downloads are being resumed with HTTP code 206.
It wouldn't be possible to start from 0 for a download that is already 40% downloaded to go back to 40% after starting from scratch.
As soon as the first sync is complete, they are correctly picking up the downloaded amount.
It just seems like the initial fills aren't being done properly.

@surafelbm
Copy link
Author

Okay, i was pretty sure they were starting from scratch when testing yesterday before submitting the Issue, but i was literally trying to record a video to send to you here to show the problem and closed the app the downloads actually resumed as expected 🙂

@zcsEason
Copy link

zcsEason commented Sep 11, 2024

@surafelbm try not to call 'begin' method when you re-attach the task(set begin to false)
image

@jacksonsmith
Copy link

Great explication folks

So should we close that issue ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants