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

background downloader poc #24

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft

background downloader poc #24

wants to merge 1 commit into from

Conversation

jowparks
Copy link
Contributor

This uses:
https://github.com/kesha-antonov/react-native-background-downloader

This is a fork of a fork, so we might want to fork ourselves and review the code 😅

In the install instructions it says you need to add code to your AppDelegate, for iOS. I skipped this, and it still seems to work 🤷

I took code from the example in the repo and massaged it to fit here as POC:

I have tested on iOS and it works out of the box. When I background the app, the downloads continue.
Clicked download, immediately background, then unbackgrounded 20 seconds later:

 LOG  task: progress {"bytesDownloaded": 735945, "bytesTotal": 20971520, "id": "1"}
 LOG  task: begin {"expectedBytes": 104857600, "headers": {"Accept-Ranges": "bytes", "Connection": "keep-alive", "Content-Length": "104857600", "Content-Type": "application/octet-stream", "Date": "Thu, 30 May 2024 23:14:33 GMT", "Etag": "\"64a6bb2c-6400000\"", "Last-Modified": "Thu, 06 Jul 2023 13:01:32 GMT", "Server": "nginx"}, "id": "3"}
 LOG  task: progress {"bytesDownloaded": 3881843, "bytesTotal": 50111000, "id": "2"}
 LOG  task: progress {"bytesDownloaded": 3701647, "bytesTotal": 20971520, "id": "1"}
 LOG  task: progress {"bytesDownloaded": 7928719, "bytesTotal": 20971520, "id": "1"}
 LOG  task: progress {"bytesDownloaded": 7846771, "bytesTotal": 50111000, "id": "2"}
 LOG  task: done {"id": "1"}
 LOG  task: done {"id": "2"}
 LOG  task: progress {"bytesDownloaded": 3227392, "bytesTotal": 104857600, "id": "3"}

@dguenther
Copy link
Member

Hmm this looks pretty useful! Do you know if the app was fully suspended there? I was looking through this blog and it sounds like when the debugger is attached, the app won't fully suspend: https://www.avanderlee.com/swift/urlsession-common-pitfalls-with-background-download-upload-tasks/#5-attaching-the-xcode-debugger-prevents-your-app-from-suspending

I'd also be curious how the performance compares to just downloading the files directly.

@jowparks
Copy link
Contributor Author

Hmm this looks pretty useful! Do you know if the app was fully suspended there? I was looking through this blog and it sounds like when the debugger is attached, the app won't fully suspend: https://www.avanderlee.com/swift/urlsession-common-pitfalls-with-background-download-upload-tasks/#5-attaching-the-xcode-debugger-prevents-your-app-from-suspending

I'd also be curious how the performance compares to just downloading the files directly.

Its hard to monitor performance for this because it starts a subsystem call to an NSURLSession, which is handled at a system level, all of the JS gets paused when the app is backgrounded and isn't run again until the app is foregrounded. I saw this when I was handling logging, nothing will happen in logging system until app is reforegrounded then all the logs for this stuff will get spit out at once. So trying to measure time while backgrounded is not trivial, maybe I missing something though.

@jowparks jowparks force-pushed the background-downloader branch from 9e4b9d4 to b102be3 Compare June 3, 2024 23:36
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

Successfully merging this pull request may close these issues.

2 participants