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

Download many files (photos, videos) in background with priority order

At first start of app I want to download all files from server and I want to continue in downloading even when user leaves app (it's not in foreground). The files I need to download are thumbnails, photos in original size, other files and video. I…
Libor Zapletal
  • 13,752
  • 20
  • 95
  • 182
10
votes
2 answers

URLSessionDidFinishEventsForBackgroundURLSession Not Calling- Objective-C

NSURLSession Delegate method URLSessionDidFinishEventsForBackgroundURLSession is not Calling ? I already enabled the Background Modes in project capabilities settings. Here is the code AppDelegate.h Method @interface AppDelegate : UIResponder…
iReddy
  • 467
  • 1
  • 5
  • 12
10
votes
0 answers

NSURLSession background download over cellular possible in iOS 8?

I need to make small downloads initiated when my app is in the background and woken up by Significant Location Changes. BUT Apples documentation of NSURLSessionConfiguration…
10
votes
3 answers

How can I check that an NSData blob is valid as resumeData for an NSURLSessionDownloadTask?

I have an app that's using background downloads with the new NSURLSession APIs. When a download cancels or fails in such a way that NSURLSessionDownloadTaskResumeData is provided, I store the data blob so that it can be resumed later. A very small…
Ian Terrell
  • 10,667
  • 11
  • 45
  • 66
9
votes
5 answers

NSURLSession background download not working

I am trying to download a number of files using NSURL background session with nsurlsessiontask. Everything works like charm when the app is running in debugging mode (when the device is connected to Xcode), doesn't work when unplugging device…
gagan sharma
  • 256
  • 1
  • 4
  • 18
8
votes
3 answers

NSURLSession Error Domain=NSPOSIXErrorDomain Code=2 "No such file or directory"

I am downloading the file in background using NSURLSession background session configuration. - (void)initBackgroundSession { self.backgroundSessionManager = [NSURLSession sessionWithConfiguration:[NSURLSessionConfiguration…
Iqbal Khan
  • 4,587
  • 8
  • 44
  • 83
8
votes
1 answer

NSUrlSessionDownloadTask - didCompleteWithError when go in background

When I force my device to go in sleep mode by pressing the power button, my background task stops by calling the delegate method didCompleteWithError with the error : The operation couldn’t be completed. Operation not permitted How can I…
ragu89
  • 335
  • 7
  • 22
8
votes
1 answer

NSURLSessionDownloadTask - read downloaded data before didFinishDownloading

I am trying to replace NSURLConnection with NSURLSession, but I found that with NSURLSession I couldn't read the intermediate data chunks like I did in NSURLConnection with the delegate method. - (void)connection:(NSURLConnection *)connection…
John
  • 2,672
  • 2
  • 23
  • 29
8
votes
2 answers

Does NSUrlSession continue file transfer if the app is killed from task manager?

I have tried various samples from the web (the last one being this one) in order to get a better understanding of NSUrlSession. What I was hoping to see: file downloads will continue even if the app that triggered them gets killed (for instance by…
Krumelur
  • 32,180
  • 27
  • 124
  • 263
8
votes
5 answers

Handling NSURLSessionDownloadTask failure

Originially I thought that if a NSURLSessionDownloadTask finishes successfully URLSession:downloadTask:didFinishDownloadingToURL: method will get called, if it fails for some reason - URLSession:task:didCompleteWithError:. It works as expected on…
7
votes
1 answer

NSURLSession background transfer not working

I’m trying to download a series of files from server to iOS app, with the intent that the download of these files happen even when the App is in the background mode. I'm using background transfer provided by NSURLSession and its series of APIs. I…
7
votes
3 answers

NSURLSessionDownloadTask not deleting the file when the app is closed by the user and the task was still active

I have a NSURLSession and a NSURLSessionDownloadTask configured for downloading a file in background, if the download task in canceled by the user all the data is deleted and the storage space the file was using is freed, but if the app is closed…
user1241006
  • 181
  • 2
  • 10
7
votes
2 answers

BackgroundSession SessionDownloadTask when locking screen, Error: NSPOSIXErrorDomain Code = 1

I have a NSURLSessionDownloadTask with a backgroundSessionConfigurationWithIdentifier. When I lock the screen, this exception occurs: Error Domain = NSPOSIXErrorDomain Code = 1 "The operation could not be completed Operation not…
JimBo
  • 73
  • 1
  • 6
7
votes
2 answers

NSURLSession URLSessionDidFinishEventsForBackgroundURLSession handler never called ios 8. OK in ios 7

I have NSURLSession that is downloading multiple files. I'm updating an ios 7 application for ios 8. It works fine in ios 7, but when complied against ios 8 The delegate meathod URLSessionDidFinishEventsForBackgroundURLSession: is never called.…
nwales
  • 3,521
  • 2
  • 25
  • 47
7
votes
2 answers

Download multiple files using iOS background transfer service

Here is the question: how to download a number of files one by one using the new Background Transfer Service (including the case when the app is suspended)? I read this awesome tutorial on objc.io and got it working for one file. But I need to…
dariaa
  • 6,285
  • 4
  • 42
  • 58
1
2
3
20 21