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

Add option to download only via wifi #500

Conversation

lyio
Copy link
Contributor

@lyio lyio commented Jul 28, 2021

  • Add allowCellular flag to the enqueue that defaults to true
  • Add separate NSURLSession on iOS that
    sets allowsCellularAccess false in its configuration
  • Schedule download requests with one of the
    two sessions depending on the flag of the download
  • Add the flag to the Android plugin and set the
    network constraints to either NetworkType.CONNECTED or NetworkType.UNMETERED depending on the value of the flag
  • Migrate sql database on Android to keep track of
    the flag

Closes #408

@lyio lyio force-pushed the feature/408-wifi-only-downloads branch from f19e9ab to 7965518 Compare July 28, 2021 12:12
@lyio lyio force-pushed the feature/408-wifi-only-downloads branch 2 times, most recently from 94b2649 to 8ea7dee Compare August 25, 2021 07:28
@kuhnroyal
Copy link

@hnvn Is this something you would consider reviewing if the conflicts are resolved?

@kuhnroyal kuhnroyal force-pushed the feature/408-wifi-only-downloads branch 2 times, most recently from 4973a4c to ce0e79e Compare October 29, 2021 13:27
@838 838 mentioned this pull request Nov 18, 2021
2 tasks
@hnvn
Copy link
Member

hnvn commented Mar 17, 2022

Thanks @lyio and @kuhnroyal for this PR. Android implementation is good for me but it seems that iOS implementation is missing configuration for DB scheme. On iOS, we have a pre-defined DB scheme in file download_tasks.sql in ios/Assets/ folder

@lyio
Copy link
Contributor Author

lyio commented Mar 18, 2022

@hnvn it works fine on iOS without updating the schema for some reason. I'll see to it that the file is updated, though.

@lyio lyio force-pushed the feature/408-wifi-only-downloads branch from ce0e79e to a0ec2c5 Compare March 21, 2022 08:39
@lyio
Copy link
Contributor Author

lyio commented Mar 21, 2022

@hnvn I have a couple of questions regarding the scheme. I have updated the binary database file to include a new column allow_cellular.

I have not seen anything in the Objective-C code suggesting that any form of migration strategy is applied. On Android the database is cleared and recreated when changes are made, but on iOS I don't see anything like that.

Am I missing something here?

Do we need to add this first? Because otherwise my changes will have no effect on existing installations as the file is only copied over if it does not exist yet.

@hnvn
Copy link
Member

hnvn commented Mar 25, 2022

The iOS implementation comes without migration solution. I currently don't find down any solution for it. That's why I am quit hesitate to add new field to DB schema. New field on DB need to release as a major update

@lyio
Copy link
Contributor Author

lyio commented Mar 25, 2022

The Android solution to the problem seems to be, to simply delete the DB and create it again when the version changes.

@bartekpacia bartekpacia changed the title #408 Add option to only download via wifi Add option to download only via wifi May 28, 2022
@lyio
Copy link
Contributor Author

lyio commented Aug 10, 2022

@hnvn do you have a migration path for iOS in mind?

lyio and others added 4 commits August 10, 2022 09:17
+ Add `allowCellular` flag to the `enqueue` that defaults to `true`
+ Add separate `NSURLSession` on iOS that 
sets `allowsCellularAccess` false in its configuration
+ Schedule download requests with one of the 
two sessions depending on the flag of the download
+ Add the flag to the Android plugin and set the 
network constraints to either `NetworkType.CONNECTED` or `NetworkType.UNMETERED` depending on the value of the flag
+ Migrate sql database on Android to keep track of 
the flag
+ Add `allow_cellular` column to the prepared
database schema
@lyio lyio force-pushed the feature/408-wifi-only-downloads branch from a0ec2c5 to f095790 Compare August 10, 2022 08:06

NSURLSessionDownloadTask *task = [self downloadTaskWithURL:[NSURL URLWithString:urlString] fileName:fileName andSavedDir:savedDir andHeaders:headers];
NSURLSessionDownloadTask *task = [self downloadTaskWithURL:[NSURL URLWithString:urlString] fileName:fileName andSavedDir:savedDir andHeaders:headers allowCellular:allowCellular];
Copy link
Contributor Author

@lyio lyio Aug 11, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

After integrating the changes to how the sessions are initialized (in a if(_isolate) condition), this always returns nil. The plugin is initialized twice, once in the foreground where no sessions are configured and once in the background where there are.

The enqueue call is made on the foreground instance though, where the sessions are missing.

I'm having trouble understanding why this is working in the example and on the master branch, @hnvn.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Disregard this, I have found the problem, I think

@lyio lyio force-pushed the feature/408-wifi-only-downloads branch from f095790 to b53fac0 Compare August 11, 2022 07:23
@lyio
Copy link
Contributor Author

lyio commented Nov 9, 2022

Due to all the changes in the meantime (especially the migration to Kotlin), I have a hard time rebasing this and still getting it to work.

I will close this PR and make a new one.

@lyio lyio closed this Nov 9, 2022
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.

Add option to download only on wifi
3 participants