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
3
votes
2 answers

NSURLSessionConfiguration backgroundSessionConfigurationWithIdentifier : Download stops after the app is pushed into background

This method sets the background object. - (void) downloadWithURL: (NSMutableArray *)urlArray pathArr: (NSMutableArray *)pathArr mediaInfo: (MediaInfo *)mInfo { bgDownloadMediaInfo = mInfo; reqUrlCount =…
nsingh
  • 31
  • 2
3
votes
2 answers

How to check resume capability of current URLSessionDownloadTask?

Currently i'm working on downloading a file from server, and this is working good. my question is how would i know that url has resume capability or not before actual download started? bellow is some code snippet, class…
Vatsal Shukla
  • 1,274
  • 12
  • 25
3
votes
0 answers

Authenticating in `NSUrlSessionDownloadTask`

I want to download files in the background using NSUrlSessionDownloadTask. To download I need to perform the following: Perform a POST to get an auth token Perform a GET to get a download URL using the auth token in the header. The URL I get back…
daramasala
  • 3,040
  • 2
  • 26
  • 33
3
votes
1 answer

What is the proper use case for NSURLSessions background sessions?

In the comments of this answer I was having a discussion about backgroundTasks which eventually led to: Use backgroundTasks for anything that isn't related to download/upload. For upload/download use NSURLSessions's backgroundSessions. Then I made…
mfaani
  • 33,269
  • 19
  • 164
  • 293
3
votes
0 answers

IOS 10.3 resumeData is broken on second pause

I'm developing an IOS app which includes file download File downloads are fully functional on iOS 9.3, but on iOS 10.3, the resumeData is broken on the 2nd pause My process steps: Start Download Pause Download (print and keep resumeData) Resume…
Semih
  • 31
  • 1
  • 4
3
votes
1 answer

URLSession delegate success methods not called, but no error

I'm using an URLSession dataTask to download a file with a URLSessionDownloadDelegate as a result handler. However, urlSession(_ session: URLSession, downloadTask: URLSessionDownloadTask, didFinishDownloadingTo location: URL) is never called.…
MasterCarl
  • 438
  • 3
  • 9
3
votes
1 answer

Many tasks (NSURLSessionDownloadTask) with a background session causes failure using AFNetworking

We have recently migrated from AFHTTPRequestOperation to NSURLSessionDownloadTask using AFURLSessionManager in AFNetworking 3. Our users have the option of downloading items that can consists of up to around 5,000 files. These files are mainly PDF…
3
votes
1 answer

Best practice to handle HTTP error with NSURLSession?

From apple's doc - (void)URLSession:(NSURLSession *)session task:(NSURLSessionTask *)task didCompleteWithError:(NSError *)error will only report the client side error through error parameter. Note: NSURLSession does not report server errors through…
Karl
  • 665
  • 4
  • 19
3
votes
3 answers

NSURLSession Download Task- Progress Bar Issue

I am working with a Non-ARC project, where i have to downloads video's, and once downloaded i will be displaying them. I am using NSURLSession for downloading it. Problem is in Progress bar. I can download first two or three file correctly through…
ChenSmile
  • 3,401
  • 4
  • 39
  • 69
3
votes
1 answer

Batch Downloading files using NSURLSession with file integrity on iOS

We have an application that downloads user contents. Our files could be big ones and usually our users download as batch. Our users having different troubles on download that described below. We want to refactor whole download process and possible…
3
votes
1 answer

NSURLSession: can't get resume data after calling cancelByProducingResumeData

I want to resume downloading after user cancels downloading or something wrong happens. But when I call cancelByProducingResumeData method, the resumeData is nil. So, I can't resume downloading. I'm sure the download link can be resumed, because our…
3
votes
2 answers

Monitoring NSURLSession after app restart

I have a prototype single-view app which monitors download tasks. I'm trying to deal with following use case: Downloads are initiated via NSURLSession while app is in foreground. NSURLSession is created with background configuration. I kill the…
mixtly87
  • 1,675
  • 15
  • 32
3
votes
2 answers

How to download large file in background using AFNetworking 3.0 and present local notification when session completes all the tasks

I am trying to download large video file in my application using AFNetworking 3.0. I couldn't find any specific document regarding how to download file in background using AFNetworking. I know AFNetworking uses AFURLSessionManager and…
3
votes
1 answer

ios - Create Session Download Task in Background

In my application I use NSURLSessionDownloadTask in the background. When the application is in foreground, I resume one download task. Later when the application is in background again, that download task completes and in the function…
AChen
  • 31
  • 3
3
votes
3 answers

Accessing the bytes from NSURLSessionDownloadTask as they are downloaded

In my app I'm currently using an NSURLSessionDownloadTask to fetch a file via HTTP. This class provides a useful delegate interface to monitor its progress and getting the bytes once the download completes via NSURLSessionDownloadDelegate, however I…
Ivan
  • 2,314
  • 3
  • 18
  • 22