I am trying to replace NSURLConnectionwith NSURLSession, but I found that with NSURLSessionI could not read intermediate pieces of data, as it was in NSURLConnection, using the delegate method.
- (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data
I used to use data before completing it. I'm kind of streaming. How can I access the downloaded data before completion NSURLSession?
I noticed that before completion there is (NSURL *)location, which is the temporary stored location of the data from NSURLSession, but can I get this URL until completion?
thank
Tried this, as Rob suggested:
NSURLSessionConfiguration *configuration = [NSURLSessionConfiguration defaultSessionConfiguration];
NSURLSession *session = [NSURLSession sessionWithConfiguration:configuration delegate:self delegateQueue:[NSOperationQueue mainQueue]];
NSURLSessionTask *task = [session dataTaskWithRequest:request];
[task resume];
However, only didRecieveResponse was called
- (void)URLSession:(NSURLSession *)session dataTask:(NSURLSessionDataTask *)dataTask didReceiveResponse:(NSURLResponse *)response completionHandler:(void (^)(NSURLSessionResponseDisposition))completionHandler
but didReceiveData is not called.
I tried changing the task for downloadTask
NSURLSessionConfiguration *defaultConfigObject = [NSURLSessionConfiguration defaultSessionConfiguration];
NSURLSession *defaultSession = [NSURLSession sessionWithConfiguration: defaultConfigObject delegate:self delegateQueue: [NSOperationQueue mainQueue]];
NSURLSessionDownloadTask * downloadTask =[defaultSession downloadTaskWithRequest:request];
[downloadTask resume];
, (didReceiveData) .
- , ?