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
0 answers

Error with SSL and NSURLSessionDownloadTask

I've had a NSURLSessionDownloadTask that worked perfectly fine for awhile, but today it stopped working and called the func URLSession(session: NSURLSession, didReceiveChallenge challenge: NSURLAuthenticationChallenge, completionHandler:…
Jeffrey
  • 1,271
  • 2
  • 15
  • 31
3
votes
1 answer

can NSURLProtocol work with NSURLSession {upload, download}dataTask

I have a custom NSURLProtocol #import @interface XXXURLProtocol : NSURLProtocol @property (nonatomic, strong) NSURLSession *session; @property (nonatomic, strong)…
3
votes
0 answers

Using SSL cert with NSUrlSession

I want to use my .pem or .pfx file to use https connection between application and server. Where should I put this file and use it to have a successful transfer of data?
Patrik Vaberer
  • 646
  • 6
  • 15
3
votes
1 answer

ios NSURLSession (default configuration) does not cache requests

I've configured the session: - (void)createSession { NSURLSessionConfiguration *sessionConfig = [NSURLSessionConfiguration defaultSessionConfiguration]; sessionConfig.requestCachePolicy = NSURLRequestReturnCacheDataElseLoad; _session…
3
votes
1 answer

Using NSURLSessionDownloadTask to display an image

I was wondering if someone could help me out. I'm trying to use NSURLSessionDownloadTask to display a picture in my UIImageView if I put the image URL into my textfield. -(IBAction)go:(id)sender { NSString* str=_urlTxt.text; NSURL* URL =…
3
votes
1 answer

How can I keep track of multiple downloads with NSURLSession?

How can I keep track of multiple downloads with NSURLSession? For example: NSURLSessionConfiguration *sessionConfiguration = [NSURLSessionConfiguration defaultSessionConfiguration]; session = [NSURLSession…
Penguin
  • 863
  • 1
  • 9
  • 22
3
votes
1 answer

NSURLSession downloadTaskWithURL returns nill

I have problem with NSURLSessionDownloadTask in my app I create few hundreds download task with code: NSURLSessionDownloadTask * task = [_urlSession downloadTaskWithURL:downloadUrl]; NSLog(@"session: %@, download task %@ for url: '%@'",_urlSession,…
sage444
  • 5,661
  • 4
  • 33
  • 60
3
votes
4 answers

iOS downloadTaskWithRequest returns nil when called on background session on iPhone, works in simulator

- (NSURLSession *)sharedBackgroundSession { static NSURLSession *sharedBackgroundSession = nil; static dispatch_once_t onceToken; dispatch_once(&onceToken, ^{ NSURLSessionConfiguration *configuration = [NSURLSessionConfiguration…
John Erck
  • 9,478
  • 8
  • 61
  • 71
2
votes
0 answers

iOS | URLSession | Download task| didWriteData not calling when user switch between apps and come

In my application, I need to download a file(size:50mb), also I need to support background downloading. By the following code I can do the download even in the background. The only problem is UI is not updating properly when I tried to switch the…
Sridhar
  • 2,228
  • 10
  • 48
  • 79
2
votes
1 answer

NSURLSessionDownloadTask continue downloading even if I kill the App

I am using the NSURLSessionDownloadTask to download a web file. When I use [NSURLSessionConfiguration backgroundSessionConfigurationWithIdentifier:] to create NSURLSessionConfiguration, I found NSURLSessionDownloadTask continue downloading even if I…
2
votes
1 answer

download file with urlsesssion

I'm trying to download using urlsession background session this is my main function func startfresh() { session = URLSession(configuration: config, delegate: self, delegateQueue: OperationQueue()) let url = URL(string:…
namaama
  • 57
  • 4
2
votes
0 answers

URLSession - optimal parallel tasks count

What is optimal number of parallel URLSessionDownloadTask in URLSession? I am trying to download multiple files (bigger files 10+MB) from different servers. I tested downloading 10 files on 40Mbps connection. When I run single download task, speed…
Martin Vandzura
  • 3,047
  • 1
  • 31
  • 63
2
votes
1 answer

urlSession download from remote url fail - CFNetworkDownload_gn6wzc.tmp appeared

I was trying to download file from remote url using urlSession. But when the download is completed an unexpected file appeared named CFNetworkDownload_gn6wzc.tmpthen i cannot open that file using uidocumentinteractioncontroller. What is that file?…
2
votes
1 answer

URLSession downloadTask behavior when running in the background?

I have an app that needs to download a file which may be rather large (perhaps as large as 20 MB). I've been reading up on URLSession downloadTasks and how they work when the app goes to the background or is terminated by iOS. I'd like for the…
bmt22033
  • 6,880
  • 14
  • 69
  • 98
2
votes
1 answer

NSData writeToFile returns NO without any error

I know many topics already exist but none of them seems to enlighten my problem. I am supposed to get a PDF file back from a JSON request on a server. The downloading task process is called but when I try to store my NSData to a file, it does not…