Skip to content

"Progress" && "Completed" callback never comes but finishes downloading the file and i can see in the storage #34

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

Open
sayem2015 opened this issue May 8, 2019 · 25 comments
Labels

Comments

@sayem2015
Copy link

sayem2015 commented May 8, 2019

"Progress" && "Completed" callback never comes but finishes downloading the file but i can see in the storage!!!

Please help i am Using nativescript with angular and i have a scene where 2 lazy loaded module both shares a component of another common module which have the downloader service...i have initiated the Downloader.init(); in the common module component.

My aim was to download from those 2 parent module using same downloader service using in that common module. Now it works fantastic when i downloads file as much as i request from the same module it works fine...but whenever i go to the 2nd module and try to download from there using the same common module it started but it never gives the callback in return like "Progress" status & "Completed" status...no error..it just got stuck but the interesting thing is that when i check the storage it actually downloads that file as expected only the callbacks get stops when i use same service from different module. And my process entirely depends on the complete status

If the demo apps cannot help and there is no issue for your problem, tell us about it

Please, ensure your title is less than 63 characters long and starts with a capital
letter.

Which platform(s) does your issue occur on?

  • Android and emulator

Please, provide the following version numbers that your issue occurs with:

"dependencies": {
"@angular/common": "~6.1.0",
"@angular/compiler": "~6.1.0",
"@angular/core": "~6.1.0",
"@angular/forms": "~6.1.0",
"@angular/http": "~6.1.0",
"@angular/platform-browser": "~6.1.0",
"@angular/platform-browser-dynamic": "~6.1.0",
"@angular/router": "~6.1.0",
"@auth0/angular-jwt": "^2.1.0",
"@nota/nativescript-webview-ext": "^5.0.0-alpha.2",
"email-validator": "^1.0.7",
"lodash": "^4.17.11",
"lodash.filter": "^4.6.0",
"nativescript-accordion": "^6.0.0-beta.2",
"nativescript-angular": "~6.1.0",
"nativescript-audio": "^5.0.1",
"nativescript-audio-ssi": "^4.0.6",
"nativescript-background-http": "^3.4.0",
"nativescript-camera": "^4.1.1",
"nativescript-cardview": "^3.1.1",
"nativescript-download-progress": "^1.1.0",
"nativescript-downloader": "^2.1.4",
"nativescript-downloadmanager": "^0.1.0",
"nativescript-drop-down": "^4.0.1",
"nativescript-feedback": "^1.3.1",
"nativescript-imagepicker": "^6.0.6",
"nativescript-iqkeyboardmanager": "~1.2.0",
"nativescript-loading-indicator": "^2.4.0",
"nativescript-localize": "^3.0.6",
"nativescript-localstorage": "^2.0.0",
"nativescript-modal-datetimepicker": "^1.1.10",
"nativescript-nativemediapicker": "^1.0.1",
"nativescript-ngx-fonticon": "^4.2.0",
"nativescript-pdf-view": "^2.0.1",
"nativescript-photo-editor": "^1.0.3",
"nativescript-plugin-firebase": "^7.6.1",
"nativescript-popup": "^1.5.0",
"nativescript-segment-view": "^1.0.6",
"nativescript-snackbar": "^4.1.0",
"nativescript-social-share": "~1.4.0",
"nativescript-status-bar": "^1.1.1",
"nativescript-svg": "^1.3.4",
"nativescript-theme-core": "^1.0.4",
"nativescript-ui-listview": "^5.0.1",
"nativescript-ui-sidedrawer": "^4.3.1",
"nativescript-unit-test-runner": "^0.3.3",
"nativescript-zip": "^3.0.0",
"reflect-metadata": "^0.1.12",
"rxjs": "~6.1.0",
"tns-core-modules": "~5.0.0",
"zone.js": "^0.8.26"
},
"devDependencies": {
"@angular/compiler-cli": "~6.1.0",
"@ngtools/webpack": "~6.2.0",
"@types/chai": "^4.0.2",
"@types/lodash": "^4.14.118",
"@types/mocha": "^2.2.41",
"@types/node": "^7.0.5",
"@nativescript/schematics": "~0.3.0",
"babel-traverse": "6.24.1",
"babel-types": "6.24.1",
"babylon": "6.17.0",
"codelyzer": "^3.0.1",
"filewalker": "^0.1.3",
"jasmine-core": "^2.6.2",
"karma": "^1.7.0",
"karma-jasmine": "^1.0.2",
"karma-nativescript-launcher": "^0.4.0",
"lazy": "1.0.11",
"nativescript-css-loader": "~0.26.0",
"nativescript-dev-android-snapshot": "0.0.11",
"nativescript-dev-appium": "~4.0.6",
"nativescript-dev-typescript": "^0.7.4",
"nativescript-dev-webpack": "^0.16.3",
"tslint": "^5.4.2",
"typescript": "~2.7.2"
}

@sayem2015 sayem2015 changed the title "Progress" && "Completed" callback never comes but finishes downloading the file but i can see in the storage "Progress" && "Completed" callback never comes but finishes downloading the file and i can see in the storage May 8, 2019
@triniwiz triniwiz added the bug label May 8, 2019
@tomfaltesek
Copy link

I'm having this same issue on iOS emulator. When I call .start(), the promise is never resolved, but the file is downloaded. I can navigate to the download path and open the file.

I don't get any progress updates from the progress callback and the promise is not resolved or rejected.

Everything seems to work fine on the Android emulator.

@sayem2015
Copy link
Author

hello @triniwiz do you have any update on this bug or any plan to get it fixed?

@darkyelox
Copy link

Debugging i found that the task.state (the task is a NSURLSessionDownloadTask in IOS) is always undefined (maybe nil in IOS) so the condition if(tas && task.state === NSURLSessionTaskState.Running) in downloader.ios.ts is never true but the progress callback from the AFNetworking library is being called as expected,, i'll keep searching for solutions

@darkyelox
Copy link

For those who have an urge for this you must at least create a fork for this project and go to downloader.ios.ts and comment all lines and codes like this:

line 86:

if (task && task.state === NSURLSessionTaskState.Running) {

from line 133 to 143:

} else if (task.state === NSURLSessionTaskState.Suspended) {
  const data = owner.downloadsData.get(id);
  if (data) {
    owner.downloadsData.set(
      id,
      Object.assign({}, data, {
        status: StatusCode.PAUSED
      })
    );
  }
}

and finally line 164:

task.state === NSURLSessionTaskState.Completed &&

With this you can have progress and completion handlers being called but maybe the status PAUSE will not work.

@tomfaltesek
Copy link

I cloned the repo and tried to replicate the issue with the demo app. I updated the demo app to download the same file as my Angular NS app and it works fine. I tried updating the info.plist to match my app and it still works fine.

I cannot replicate with the demo app, for some reason.

@tomfaltesek
Copy link

When using the plugin with my Angular NS app, as @darkyelox stated, task.state is always undefined. When running my download code from the demo, task.state has a state value.

@erkanarslan
Copy link

@triniwiz I have this problem too. Is there going to be a fix for this?

@erkanarslan
Copy link

@tomfaltesek @triniwiz I found out that this plugin does not work with Nativescript 5.3.0+. Latest version of the Nativescript that works with this plugin is 5.2.2.

You can test it by downgrading NS version:

npm remove -g nativescript
npm i [email protected]
npm install [email protected]
tns platform remove ios
tns platform add ios

@erkanarslan
Copy link

I made a temporary fix but you have to edit a file in node_modules folder.

Open node_modules/nativescript-downloader/downloader.ios.js. Paste this code block directly above dispatch_async function:

if(progress.finished) {
	task.state = 3;
}
else if(progress.paused) {
	task.state = 1;
}
else {
	task.state = 0;
}

The related part of the file will look like this:

var task = download.downloadTaskWithRequestProgressDestinationCompletionHandler(request, function (progress) {
	if(progress.finished) {
		task.state = 3;
	}
	else if(progress.paused) {
		task.state = 1;
	}
	else {
		task.state = 0;
	}

	dispatch_async(main_queue, function () {

I hope this helps anybody who faces this problem until this library is updated.

@MichaelSmi
Copy link

MichaelSmi commented May 31, 2019

Thanks @erkanarslan for the workaround. But sadly this throws an error all the time:
JS ERROR TypeError: null is not an object (evaluating 'owner.downloadsData')
The error occurs some lines below your pasted modification:

var task = download.downloadTaskWithRequestProgressDestinationCompletionHandler(request, function (progress) {
            if(progress.finished) {
                task.state = 3;
            }
            else if(progress.paused) {
                task.state = 1;
            }
            else {
                task.state = 0;
            }
            dispatch_async(main_queue, function () {
                var owner = ref.get();
                if (task && task.state === 0) {
                    var current = Math.floor(Math.round(progress.fractionCompleted * 100));
                    **if (owner.downloadsData.has(id)) {**
...

I also tweaked a bit around this code lines but with no success :(
I'd really appreciate to have a fixed yersion working with latest {N}.

@erkanarslan
Copy link

I had this problem too. But when I reinstalled the package and applied my changes it worked. Try reinstalling it.

@tomfaltesek
Copy link

Just submitted a PR (#35) that fixes the task state issues with iOS in NS 5.4.0+. The download speed doesn't work, but at least the plugin is usable.

@MichaelSmi
Copy link

@triniwiz @acharyaks90 @matecode Will we get a new release with the fixes from @tomfaltesek PR #35 ?

@acharyaks90
Copy link
Contributor

@triniwiz Please release

@MichaelSmi
Copy link

@triniwiz push ⇪

@adetayoadeyemi
Copy link

please release, great work everyone

@tomfaltesek
Copy link

FYI to those watching this issue -- I tried switching to this plugin, for now: https://github.com/tobydeh/nativescript-download-progress

It works with the latest NS 5.4.0+ on both platforms.

@silviosan
Copy link

silviosan commented Jul 10, 2019

@triniwiz It would be great if you could please release a new version of your plugin to get it working again with NS >= 5.4.0.

@triniwiz
Copy link
Owner

So this bug is related to NativeScript/ios-jsc#1149 an using the fix here should will help NativeScript/ios-jsc#1149 (comment)

@silviosan
Copy link

@triniwiz Thank you very much for your hint to the bug inside the iOS-runtime! Hopefully it will be fixed there soon.

@alemartins414
Copy link

alemartins414 commented Aug 1, 2019

Still having this issue. Is there any workaround for android?

@7ammer
Copy link
Contributor

7ammer commented Sep 11, 2019

Android is also having the same issue :(

@sido420
Copy link

sido420 commented Sep 29, 2020

Same issue on Android

@sido420
Copy link

sido420 commented Sep 30, 2020

Did some debugging, looks like task in following code in downloader.android.js is invalid and does not exist in taskIds Map.

        onUIProgress: function (task, currentBytes, totalBytes, speed) {

However, download seems to work the first time after app is launched.

@sido420
Copy link

sido420 commented Sep 30, 2020

it looks like the value in task inside onUIProgress() is valid but the owner.taskIds Map contains invalid entries from the first download. However, Downloader.prototype.createDownload() correctly populates the taskIds map to contain new taskId. The local this.taskIds (and possibly maps) map contain different content in methods.

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

No branches or pull requests