See Apple documentation for Swift (URLSessionDataTask) and Objective C.
Questions tagged [nsurlsessiondatatask]
265 questions
2
votes
0 answers
NSURLSession Show Tasks In Suspended State?
I know that invoking getTasksWithCompletionHandler on an NSURLSession:
Asynchronously calls a completion callback with all outstanding data,
upload, and download tasks in a session.
However, from experimentation, I can see the data, upload, and…

Max MacLeod
- 26,115
- 13
- 104
- 132
2
votes
1 answer
How to aggregate response from multiple NSURLSessionDataTasks?
I am trying to aggregate the data from multiple NSURLSessionDataTasks that will run concurrently.
__block NSMutableDictionary *languageDetails = [NSMutableDictionary new];
[repos enumerateObjectsUsingBlock:^(NSDictionary *repoDict, NSUInteger idx,…

Anish Basu
- 145
- 2
- 5
2
votes
2 answers
NSURLSession delegate didCompleteWithError not called
I have the below implementation of NSURLSession .
NSURLSessionConfiguration *configuration = [NSURLSessionConfiguration defaultSessionConfiguration];
self.session = [NSURLSession sessionWithConfiguration:configuration
…

CodeTry
- 312
- 1
- 19
2
votes
2 answers
Will NSURLRequest timeout value overrides NSURLSessionConfiguration timeoutIntervalForRequest value?
I am creating a NSURLSession object with timeoutIntervalForRequest configuration = 120 seconds. After this I am creating a NSURLSessionDataTask object and calling the method dataTaskWithRequest:completionHandler. Here one input parameter is a…

Advaith
- 1,087
- 3
- 12
- 31
2
votes
0 answers
Retry an NSURLSessionDataTask request after re-authorizing (AKA NSInvocation equivalent in Swift)
TL;DR version: What is the nearest equivalent to NSInvocation - or similar way to package up a method call, including arguments - in Swift?
Background: I have a ServerController object which is used across my app to make requests to an API. The…

Andrew Ebling
- 10,175
- 10
- 58
- 75
1
vote
1 answer
Ambiguous use of 'dataTask(with:completionHandler:)'
I updated the Xcode to 14.3 and when I tried to run a project, I am getting this error:
"Ambiguous use of 'dataTask(with:completionHandler:)'"
Do you know how I can fix this issue ?
extension URLSession: URLSessionProtocol {
func dataTask(with…

Louiza A
- 23
- 6
1
vote
1 answer
Swift async cancel like URLSession
when i use callback function with URLSession, i can use URLSessionDataTask to cancel a task
let task = URLSession.shared.dataTask(with: URLRequest(url: URL(string: "")!)) { data, response, error in
// handle response
}
task.cancel()
when i use…

bomo
- 39
- 5
1
vote
1 answer
How to print the api response to the console? Xcode 14
I am learning about API's and decided to practice using them by writing a simple function to call an api and print the response. The issues I am having is that the response is not printing to the console. I am also new to Swift but watched a couple…

User534t
- 11
- 3
1
vote
0 answers
Need clarification between URLError. dataNotAllowed and URLError.notConnectedToInternet
I tried to handle URLSession dataTask error. When dataTask is started without internet connection , i'm getting URLError.dataNotAllowed error. When will I get URLError.notConnectedToInternet ?

iroh
- 23
- 5
1
vote
1 answer
Getting nil data when try to cancel a task and restart it again Swift
What I am trying to do:
Sometimes my URLSession call request takes a too long time to give a response back. That's why I am trying to call the call request again if it doesn't give a response back within 60 seconds. After 60 seconds it will cancel…

Tulon
- 4,011
- 6
- 36
- 56
1
vote
1 answer
Do I need place urlsession datatask on another DispatchQueue or it's done automatically?
Didn't have any experience with datatasks and urlsessions before. So I'm curious. Case is - trying to have a table with infinite scroll. When this method called
tableView(_ tableView: UITableView, prefetchRowsAt indexPaths: [IndexPath])
from…

Alexander
- 396
- 1
- 11
1
vote
2 answers
url data task is not showing the right content when parsed with SwiftSoup? Swift 5
I am pretty new to swift and have an app that performs a simple url data task to parse the html contents of that website. I was trying to load certain elements but wasn't getting the content that I was seeing on the website when I inspect it…

aadi sach
- 51
- 5
1
vote
1 answer
URLSession dataTask long delay
When I'm requesting API from my code I got response after 4-6sec which is way too long. From Postman I'm getting response after 120ms. Is that something in my code goes wrong?
here is my code, I'm checking time between those two prints:
func…

Gorthez
- 391
- 3
- 12
1
vote
1 answer
Asynchronous thread in Swift - How to handle?
I am trying to recover a data set from a URL (after parsing a JSON through the parseJSON function which works correctly - I'm not attaching it in the snippet below).
The outcome returns nil - I believe it's because the closure in retrieveData…

MRoot
- 45
- 6
1
vote
0 answers
Track the progress of more than one data tasks at the same time in swift
I am downloading a couple of images and want to show the user some kind of progress until its finished. I found a way to track the progress of data tasks from this question get progress from dataTaskWithURL in swift but it only tracks the download…

JPJerry5
- 107
- 10