See Apple documentation for Swift (URLSessionDataTask) and Objective C.
Questions tagged [nsurlsessiondatatask]
249 questions
19
votes
1 answer
Does NSURLSession for HTTP data task (NSURLSessionDataTask) runs in background thread or we will have to provide the queue?
I started to use NSURLSession by avoiding NSURLConnection now a days as it's a new and elegant API provided by Apple. Previously, I used to put call NSURLRequest in GCD block to execute it in background. Here is how I used to do in…
![](../../users/profiles/1374327.webp)
NSPratik
- 4,294
- 5
- 43
- 74
14
votes
4 answers
Custom NSURLProtocol with NSURLSession
I'm trying to implement this tutorial which implements a custom NSURLProtocol with NSURLConnection.
https://www.raywenderlich.com/76735/using-nsurlprotocol-swift
It works as expected, but now that NSURLConnection is deprecated in iOS9, I'm trying to…
![](../../users/profiles/1248807.webp)
kupilot
- 465
- 1
- 3
- 13
12
votes
2 answers
Pattern for retrying URLSession dataTask?
I'm fairly new to iOS/Swift development and I'm working on an app that makes several requests to a REST API. Here's a sample of one of those calls which retrieves "messages":
func getMessages() {
let endpoint = "/api/outgoingMessages"
let…
![](../../users/profiles/685869.webp)
bmt22033
- 5,639
- 10
- 58
- 88
11
votes
4 answers
NSURLSessionDataTask timeout subsequent requests failing
I am creating a NSMutableRequest:
self.req = [NSMutableURLRequest requestWithURL:myURL cachePolicy:NSURLRequestReloadIgnoringCacheData timeoutInterval:10.0];
The timeout is set to be 10 seconds because I don't want the user to wait too long to get…
![](../../users/profiles/2762447.webp)
nicky_1525
- 919
- 1
- 10
- 23
10
votes
1 answer
NSURLSession HTTP/2 memory leak
This My Test cases, point out that when using NSURLSession with a HTTP/2 connection there is memory problem.
test1: iOS 9. HTTP/2 server
I use NSURLSession to upload 10M file to a HTTP/2 server, if the file uploaded completed everything is ok, But…
![](../../users/profiles/1656395.webp)
rotoava
- 575
- 6
- 18
8
votes
1 answer
Throw error from dataTask completionHandler
In swift how do I throw an error within a completion handler like this:
let task = URLSession.shared.dataTask(with: request as URLRequest, completionHandler: {
(data, response, error) in
do {
//something
…
![](../../users/profiles/1240649.webp)
Wayneio
- 2,866
- 4
- 36
- 55
8
votes
4 answers
NSMutableURLRequest setTimeoutInterval not working in ios 11.0
I am using URL background session for pdf uploading as data stream, using ios version > 9.0. I am setting timeout interval of 300 sec. Its not working at all. After 10 seconds it gets timeout error.
Piece of code is given below
NSTimeInterval…
![](../../users/profiles/1305001.webp)
Warewolf
- 12,416
- 4
- 55
- 85
7
votes
2 answers
How to sync serial queue for URLSession tasks?
Using XCode-8.2.1, Swift-3.0.2 and iOS-10.2.1,
I am trying to call two different URLSession.shared.dataTasks (the first is a simple URL-request and the second is a POST-request).
Since my first dataTask delivers a result that is needed in the…
![](../../users/profiles/3826232.webp)
iKK
- 4,553
- 5
- 45
- 93
7
votes
3 answers
Get the size of an AVAssetDownloadTask before downloading
I'm currently implementing offline streaming with FairPlay streaming. Therefor I'm downloading streams using an AVAssetDownloadTask.
I want to give the users feedback about the size of the download which starts to begin:
Are you sure you want to…
![](../../users/profiles/1485701.webp)
Antoine
- 21,544
- 11
- 81
- 91
6
votes
2 answers
NSURLSessionTask. Suspend does not work
This is what Apple's documentation says regarding suspend method of NSURLSessionTask class
A task, while suspended, produces no network traffic and is not subject to timeouts.
Ok. So I'm running the following simple code:
let url =…
![](../../users/profiles/994107.webp)
Andrey Chernukha
- 20,316
- 16
- 89
- 153
5
votes
1 answer
How to tell the main thread that a URLSessionDataTask has finished
Using Swift 4, I have this code that attempts a POST request to a REST API:
spinner.startAnimation(self)
btnOk.isEnabled = false
btnCancel.isEnabled = false
attemptPost()
spinner.stopAnimation(self)
btnOk.isEnabled = true
btnCancel.isEnabled =…
![](../../users/profiles/7347751.webp)
David Mordigal
- 723
- 8
- 20
5
votes
4 answers
Network requests are failing - NSURLSession - App Sandbox - Xcode 9
I have a simple GET request that I am trying to run in my macOS application. However I keep getting the following error:
A server with the specified hostname could not be found.
The URL I am trying to download JSON data from…
![](../../users/profiles/1598906.webp)
Supertecnoboff
- 5,886
- 9
- 50
- 94
5
votes
1 answer
Implementing completion handlers for backgroundSession.uploadTask
I have (almost) successfully implemented URLSessionDelegate, URLSessionTaskDelegate, and URLSessionDataDelegate so that I can upload my objects in the background. But I'm not sure how to implement completion handlers, so that I can delete the object…
![](../../users/profiles/2183009.webp)
Frederik
- 436
- 5
- 22
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…
![](../../users/profiles/181947.webp)
brian.clear
- 5,154
- 2
- 39
- 60
4
votes
1 answer
is session.dataTask asynchronous in swift?
I am making requests to my server using the following code:
let configuration = URLSessionConfiguration.default
let session = URLSession(configuration: configuration)
let dataTask = session.dataTask(with: request as URLRequest) { (data, response,…
![](../../users/profiles/4718413.webp)
alionthego
- 5,738
- 7
- 38
- 74