Questions tagged [nsurlsessiondownloadtask]

An NSURLSessionDataTask is a concrete subclass of NSURLSessionTask. The methods in the NSURLSessionDataTask class are documented in NSURLSessionTask Class Reference.

An NSURLSessionDataTask behaves differently from other subclasses in several subtle ways:

  • An NSURLSessionDataTask object returns data directly to the app rather than through a file (as a download task would).
  • During upload of the body data (if your app provides any), the session periodically calls the delegate’s URLSession:task:didSendBodyData:totalBytesSent:totalBytesExpectedToSend: method with status information. (It also calls this method for upload tasks.) Upon receiving an initial response, the session calls the delegate’s URLSession:dataTask:didReceiveResponse:completionHandler: method to provide your app with the opportunity to convert the transfer into a download task depending on the returned MIME type and other information.

  • If your app converts the transfer into a download task, the session calls the delegate’s URLSession:dataTask:didBecomeDownloadTask: method to provide your app with the new download task.

  • During the transfer, the session calls its delegate’s URLSession:dataTask:didReceiveData: method with data objects containing bits of data as it is received. Upon completion, the session calls its delegate’s URLSession:dataTask:willCacheResponse:completionHandler: method to determine whether the response should be cached.

  • If this delegate method is provided, it must call the provided completion routine; otherwise, your app leaks memory.

  • If this delegate method is not provided, the default behavior is to use the caching policy specified in the session’s configuration object.

  • Unlike download tasks, requests made through NSURLSessionDataTask objects cannot be resumed after they are canceled.

309 questions
2
votes
1 answer

Cannot get data from URLSessionTaskDelegate

I am trying to add background fetch capability to my app. Currently, the delegate function urlSession(_ session: URLSession, downloadTask: URLSessionDownloadTask, didFinishDownloadingTo location: URL) is called after the network call is complete,…
Andrew Walz
  • 890
  • 2
  • 8
  • 27
2
votes
1 answer

URLSessionDownloadDelegate didFinishDownloadingTo not called in background

I start a download in an action extension (ActionRequestHandler) like this: private lazy var urlSession: URLSession = { let config = URLSessionConfiguration.background(withIdentifier: "de.stefantrauth.Downloader") …
2
votes
1 answer

Is it a good approach to use multiple download tasks with a single URLSessionDownloadDelegate confirming class?

Currently I'm working on implementing a network manager for handling download and upload tasks. I have a class that confirms to URLSessionDownloadDelegate, URLSessionDelegate. The problem I'm facing is I'm using a single session object which is used…
jegadeesh
  • 875
  • 9
  • 22
2
votes
1 answer

NSURLSessionDownloadTask continues download while suspended

I'm using NSURLSessionDownloadTask to download files. At one point in the application it is necessary to pause the download for a short time and then resume it. I tried using the suspend method for pausing the download but the task continuous to…
Kristiina
  • 523
  • 2
  • 10
2
votes
1 answer

NSURLSessionDataTask not called after NSURLSessionDownloadTask in the same NSURLSession in iOS background

My iOS app works in the following way I have an array of audio file names, I check whether the file is present. If it's present it starts playing it. Once finished I start playing the next audio. If the file is not present I make a…
2
votes
2 answers

Should I use operation queue for this complete scenario?

I need to perform a scenario with the following steps: To make a network call with some search parameters provided by the user Then, to parse its JSON response and create model entities Then, for each entity created and if it has an associated…
2
votes
2 answers

ios objective c : How to get NSURLSession to return Content-Length(http header) from server

I already tried How to get NSURLSession to return Content-Length(http header) from server. Objective-c, ios - (long long) getContentLength { NSURLSessionConfiguration *config = [NSURLSessionConfiguration defaultSessionConfiguration]; …
S. S
  • 169
  • 3
  • 16
2
votes
0 answers

how to get status of downloads using HCDownload

I am using the code below to download multiple files and the files are getting downloaded properly. HCDownloadViewController *dlvc = [[HCDownloadViewController alloc] init]; dlvc.downloadDirectory = @"/var/mobile/Library/Downloads"; dlvc.delegate =…
Fahim Parkar
  • 30,974
  • 45
  • 160
  • 276
2
votes
2 answers

NSURLSession background transfer : Callback for each video downloaded from a queue

I am using background transfer service for downloading multiple videos using NSURLSession. Downloading is working fine when the App is in background mode and I am satisfied with it. My problem is, I want callback for each video downloaded from a…
2
votes
1 answer

AFNetworking / NSURLSession timeouts when downloading many files

In my app the user has the possibility to download many files at once. Those files are about 2MB each. As the user can choose as many files at once as he likes, I set my operationQueue to only allow 2 concurrent operations. Here's how I set up my…
Georg
  • 3,664
  • 3
  • 34
  • 75
2
votes
1 answer

How to download video from youtube and save (objective c)?

How can I download videos from you-tube and save in my app folder. I have videoID, but don't have working code. I found this link but the code from this link is not working for me. Save Youtube video to iPhone in the app If any one have any working…
2
votes
0 answers

Using NSURLSessionDataTask, can I resume downloading a file, even if user comes back after quitting an App?

Suppose, I am downloading a file of 300 MB using NSURLSessionDownloadTask or NSURLSessionDataTask (at present, I don’t know which is the best choice in my case). User quits the App or App suddenly crashed while 250 MB were downloaded. When next…
2
votes
1 answer

downloadTaskWithURL how to get the actual data

I am trying to downlaod an image. This is the link of the image https://www.google.it/images/branding/googlelogo/2x/googlelogo_color_272x92dp.png what I did is: let url = NSURL(string:…
sarah
  • 1,201
  • 1
  • 9
  • 29
2
votes
1 answer

No data in location returned from URLSession(session:downloadTask:didFinishDownloadingToURL location)

I am using a standards background session for handing a background fetch. The operations starts fine and callback: URLSession(session:downloadTask:didFinishDownloadingToURL location) is regularly called, yet when I check the contents of the…
Fabrizio Bartolomucci
  • 4,948
  • 8
  • 43
  • 75
2
votes
1 answer

Backgroundfetch for more than 30seconds

I'm developing an iOS App, where I have to download multiple zip-Bundles. To handle the downloads I'm using an internal C++ http-framework. Is there any posibillity to do an Background-Fetch for more than 30sec? One possibility ist the usage of…