See Apple documentation for Swift (URLSessionDataTask) and Objective C.
Questions tagged [nsurlsessiondatatask]
265 questions
5
votes
2 answers
iOS8: NSURLSession: NSURLSessionDataTask 'Client closed connection before receiving entire response'
I use iOS BACKGROUND FETCH n BACKGROUND TRANSFER to update our app.
When we download an MP4 as part of a large download of lots of files the download can stop suddenly and get error:
'Client closed connection before receiving entire response'
http…

brian.clear
- 5,277
- 2
- 41
- 62
4
votes
1 answer
Swift Combine in UIKit. URLSession dataTaskPublisher NSURLErrorDomain -1 for some users
After switching our API Client to Combine we start to receive reports from our users about error "The operation couldn’t be completed (NSURLErrorDomain -1.)" which is the error.localizedDescription forwarded to UI from our API client.
Top level api…

George
- 643
- 9
- 23
4
votes
1 answer
In Swift, how do you get the error type from UrlSession
I have the following code in my network logic:
let task = urlSession.dataTask(with: request) { [weak self] (data, response, error) in
if let error = error {
if error.localizedDescription.contains("The request timed out") {
//…

Fred
- 381
- 5
- 17
4
votes
1 answer
URLSession.shared.dataTask correct way to receive data
Good day!
I am a little confused in trying to find the correct sequence in checking received (data, response, error) from dataTask and doing some special error handling.
Usually we have URLSession looking like this:
class HTTPRequest {
static…

Konstantin
- 197
- 3
- 12
4
votes
0 answers
Trying to understand URLSession dataTask cacheing
I am downloading images from a website using the code below that caches images. Do I need to store images in the apps directory to permanently save them?
After running this code, I can turn my device on airplane mode, restart it, and open the app…

Bobby
- 6,115
- 4
- 35
- 36
4
votes
1 answer
OCMock -[NSURLSessionDataTask response] unrecognized selector crash in iOS 9
The problem
We use OCMock for mock objects in many of our unit tests. As part of our tests to see how our code responds to server responses, we create an NSURLSessionDataTask object and later try to use the "response" property on it.
The plot…

BergQuester
- 6,167
- 27
- 39
4
votes
1 answer
NSURLSessionTask authentication challenge completionHandler and NSURLAuthenticationChallenge client
I am implementing a custom NSURLProtocol, and internally want to use NSURLSession with data tasks for internal networking instead of NSURLConnection.
I have hit an interesting problem and wonder about the internal implementation of the challenge…

Léo Natan
- 56,823
- 9
- 150
- 195
3
votes
1 answer
SSL Error occurs in URL Session data task call back in certain devices only
For some users our app is throwing NSError while trying to call a secured server API using URLSession data task. Below is the detail of the error:
error-domain: NSURLErrorDomain
nserror-code: -1202
NSErrorPeerCertificateChainKey: (…

med
- 369
- 1
- 4
- 18
3
votes
4 answers
How to make URLSession to work when app is moved to background
On a button click, I have to implement multiple API calls to get the data and write that data to file. I am using Operation Queue and URLSession datatask to implement this. While this API calls are in process, If the app is placed to background…

Kalyan
- 263
- 5
- 22
3
votes
0 answers
My App received nil Data during a HTTPS URLSessionDataTask
My iOS application's view controller simply GET requests a JSON from my backend API server using Swift 3 code and Foundation classes URL, URLRequest, URLSessionDataTask.
My backend API server (sesapi.infinnovation.co) supports HTTPS over TLS 1.2…

Swarup Ghosh
- 55
- 5
3
votes
1 answer
How to cancel NSURLSession when moving to another UIViewController
I am using NSURLSession for API call. Once API gets hit, before getting response I am moving to another view controller. How to stop all NSURLSession running in the current view controller? Kindly guide me.
My Sample code is not working. If I move…

McDonal_11
- 3,935
- 6
- 24
- 55
3
votes
2 answers
dataTaskWithRequest:completionHandler: is deprecated
I'm using AFNetworking in my project to get the data from REST api.
But when I'm using the method which described in Github I'm getting warning.
Here is my code :
NSURLSessionConfiguration *configuration = [NSURLSessionConfiguration…

Himanth
- 2,381
- 3
- 28
- 41
3
votes
1 answer
NSURLSessionDataTask in background session
I would like to make an empty POST request and read the response headers while my iOS app is in the background. Looking at the documentation it explicitly states that Upload and Download tasks are supported in the background, but there are two…

JustinHK
- 758
- 1
- 6
- 19
3
votes
3 answers
returning a value from asynchronous call using semaphores
I need to use NSURLSession to make network calls. On the basis of certain things, after I receive the response, I need to return an NSError object.
I am using semaphores to make the asynchronous call behave synchronously.
The problem is, the err is…

Shradha
- 991
- 3
- 13
- 38
2
votes
1 answer
NSURLSessionDataTask does not work on macOS, "A server with the specified hostname could not be found."
Why does dataTaskWithURL work on iOS, but not on macOS?
The error message is:
Client-Error: A server with the specified hostname could not be found.
My routine is as follows:
- (void)loadHTML {
NSString *urlString =…

Tom
- 654
- 6
- 10