mzeeshanid / MZDownloadManager

This download manager uses NSURLSession api to download files. It can download multiple files at a time. It can download large files if app is in background. It can resume downloads if app was quit.
BSD 3-Clause "New" or "Revised" License
1.12k stars 238 forks source link

Background download issues #30

Open andrealufino opened 7 years ago

andrealufino commented 7 years ago

Hello. I'm using MZDownloadManager to perform around 500 downloads in my app. I'd like to be able to let the user exit the app during the downloads, but I'm not sure how to do it. I'm able to make this work on the Simulator without any specific setting, but not on the real device. I've set up the Background Modes capabilities for my target. Do you have any suggestion?

mzeeshanid commented 7 years ago

I'd like to be able to let the user exit the app during the downloads Did you mean force quit the app? Or did you mean when app is in background?

andrealufino commented 7 years ago

App in background, not force quit

mzeeshanid commented 7 years ago

If it is working in simulator then it should also work in real device. I am not sure whats going on. Make sure that background modes are enabled in Settings in your device.

andrealufino commented 7 years ago

Everything is set on device. Basically my code add a download task every time a new one is finished, so I don't load all my 500 tasks once, but one per time. I don't know if this information can help you.

sivanookala1979 commented 7 years ago

how to see the files in custom directory in my iphone.

mohammadzk commented 7 years ago

hi is there a way to resume downloads after force quitting the app and opening it again

mzeeshanid commented 7 years ago

When user force quits app and relaunch the app this delegate method got called func URLSession(_ session: Foundation.URLSession, task: URLSessionTask, didCompleteWithError error: NSError?) and in error's info there is a key i.e NSURLErrorBackgroundTaskCancelledReasonKey and in this case its value will be NSURLErrorCancelledReasonUserForceQuitApplication. There are additional keys in that user info try to find out the resume data from the error and restart the task with the resume data.

mohammadzk commented 7 years ago

ok thank you very much for wonderful library 👍

NorbertSzydlowski commented 7 years ago

+1 I have issue with background download (unknown error).

I am running app from xcode in my device, background is working. I will open second app and go back again to main app, download work.

I launch app from icon (after installed) and make the same steps as above, error trigger.

Any idea?

ugochirico commented 7 years ago

Hi, I'm trying to implement a way to resume a download task after the app has been quit by the user because I need to download a large file (300MB more or less).

can you share a code snippet that shows how to do that?