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
6
votes
1 answer

iOS 13 background download issue

I have a syncing functionality, where a series of downloads happens in the background. For that, I create a URLSession instance with background configuration as below: let config = URLSessionConfiguration.background(withIdentifier:…
Harish J
  • 525
  • 1
  • 4
  • 16
6
votes
1 answer

NSURLSession HTTPMaximumConnectionsPerHost not working as expected

I am trying to download .ts files of a .m3u8 Video. I have created a download task for each of the .ts url and the session configuration HTTPMaximumConnectionsPerHost property set to 4: NSURLSessionConfiguration *sessionConfig =…
6
votes
1 answer

NSURLSessionDownloadTask stalls in background, slow to recover in foreground

I am creating a background session using this code... let configuration = URLSessionConfiguration.background(withIdentifier: UUID().uuidString) configuration.sessionSendsLaunchEvents = true configuration.isDiscretionary = false …
user250818
6
votes
1 answer

NSURLSession downloadTask not releasing memory

Due to the customer can't implement just few downloads in his server in a short time and backgroundDownloadTaks were very inconsistent when there are so much files (500-1000 downloads) I decide to use NSURLDownloadTask without background…
Rotten
  • 742
  • 10
  • 24
6
votes
1 answer

Download large number of files in background in iOS

I have an app in which I have to download a large number of files, from 400 to 900 files that are about 1GB total. Which is the best approach to accomplish this? One NSURLSession and all task enqueued in it? One NSURLSession and enqueue tasks by…
Rotten
  • 742
  • 10
  • 24
6
votes
1 answer

NSURLSession getting intermittent SSLHandshake failed (-9810) error

Download image from secure URL, behind a security wall. A URL like https://foo.com/bar.png Sometimes I'm getting a SSLHandshake error. Sometimes the error happens once, but sometimes the error is constant and I'm unable to download the…
DBD
  • 23,075
  • 12
  • 60
  • 84
5
votes
1 answer

Error __NSCFLocalDownloadFile error 2 creating temp

NSURLSession *session = [NSURLSession sessionWithConfiguration:[NSURLSessionConfiguration defaultSessionConfiguration]]; @synchronized (session) { [[session downloadTaskWithURL:attachmentURL completionHandler:^(NSURL…
5
votes
1 answer

URLSession downloadTask much slower than internet connection

I'm using URLSession and downloadTask to download a file in the foreground. The download is much slower than expected. Other posts I found address the issue for background tasks. let config =…
Guig
  • 9,891
  • 7
  • 64
  • 126
5
votes
3 answers

How to get a response from NSURLSessionDownloadTask downloadTaskWithRequest

Some background first: Application is supposed to grab files from AWS S3 server. In order to do that, first step of that process is to go to local server and get the name of the file and some other information from it. After that step we have a…
5
votes
2 answers

NSURLSession with invalid resume data

I use [NSURLSessionConfiguration defaultSessionConfiguration] to config my url session. I pause a task by calling cancelByProducingResumeData: to produce a resume data, and save it to the disk. When I want to restart the task, I call…
4
votes
2 answers

Trying to understand URLSession Authentication challenges

I am attempting to download a PDF from a URL. private func downloadSessionWithFileURL(_ url: URL){ var request = URLRequest(url: url) request.addValue("gzip, deflate", forHTTPHeaderField: "Accept-Encoding") let sessionConfig =…
RyanTCB
  • 7,400
  • 5
  • 42
  • 62
4
votes
0 answers

URLSession downloadTask w/ block get download progress

When I conform to the URLSessionDownloadDelegate The following delegate method can be used to get the progress of the download. urlSession(_ session: URLSession, downloadTask: URLSessionDownloadTask, didWriteData…
Brandon A
  • 8,153
  • 3
  • 42
  • 77
4
votes
1 answer

URLSessionDownloadTask in background never triggers handle(_ backgroundTasks: Set) for WKURLSession​Refresh​Background​Task

Trying to understand why, when scheduling a background URLSessionDownloadTask in WatchKit 3.0. the func handle(_ backgroundTasks: Set) never fires for WKURLSession​Refresh​Background​Task, but other tasks come through like…
Nate Potter
  • 3,222
  • 2
  • 22
  • 24
4
votes
1 answer

URLSession Cancellation in swift while auto search

My moto is Auto search, I have been trying with URLSession, When i am trying to search slowly the requests are handled as expected(when there is no text the response is empty i mean the placesarray) but when i am trying to clear the text or hit any…
iOSDev
  • 412
  • 10
  • 30
4
votes
2 answers

Why previous finish of download fires, after stop app and running again?

I track downloads using two arrays, to track my downloads and to know where to save them: private var filesToDownload: NSMutableArray = [] private let startedDownloads: NSMutableArray = [] When a download finishes remove them from both arrays and…
user2834172
  • 861
  • 1
  • 9
  • 17
1 2
3
20 21