Questions tagged [nsurlsessiondatatask]

See Apple documentation for Swift (URLSessionDataTask) and Objective C.

265 questions
1
vote
0 answers

Do you need to use URLSession's dataTask(with: URL) inside of an Operation class's main() method?

Do you need to use URLSession's dataTask(with: URL) inside of an Operation class's main() method? For example: class Downloader: Operation { let postDetailsPage: PostDetailsPage init(_ postDetailsPage: PostDetailsPage) { …
1
vote
2 answers

Should I choose URLSessionDataTask or URLSessionDownloadTask for getting image

I use URLSession and URLSessionDataTask to get an image from server and display it in an app. I had a look here. It looks like URLSessionDownloadTask has more options. Currently I use the following code for getting the image: let task =…
surToTheW
  • 772
  • 2
  • 10
  • 34
1
vote
3 answers

JSON networking request not entering URLSession.shared.dataTask

I am having problems finding out why my dataTask returns an empty result. While going through My NetworkingManager class it appeared that it never enters the URLSession.shared.dataTask. Does anyone know why? Her is my NetworkingManager which is…
Boglinger
  • 15
  • 6
1
vote
0 answers

how to handle URLSession.shared.dataTask properly

Hi developers im having some issue or misplaced tasks so i had to develop a framework with some functions this is my main FUNCTION where the issue began     func saveDataDevice(idPos: String, macAddress: String) {         // this first function…
ZeroCooL
  • 79
  • 5
1
vote
0 answers

How to fix the Background download problem in IOS over cellular data

I have a ebook related app live on app store. This app downloads big files (ranging from ~100MB - 1GB) in background mode. Out of 100 users 10 users have reported problems with the download when they are downloading over cellular data. We checked…
ronghester
  • 23
  • 2
1
vote
2 answers

Is there a way to force ios system clear some (or all) app's cache?

My app downloading and saving some support data to 'Library/Caches' directory. According to documentation, Use this directory to write any app-specific support files that your app can re-create easily. Your app is generally responsible for…
1
vote
1 answer

Xamarin: NSMutableUrlRequest and NSUrlRequest with POST method and headers and data?

I have a Xamarin project where I am able to make GET calls without headers to something like "reqres.in" API like: public Task GetData() { TaskCompletionSource tcs = new TaskCompletionSource(); NSUrl url = new…
1
vote
3 answers

iOS Swift - URLSessionDataTask doesn't get updated JSON data on refresh

I have a simple app where I get data from a JSON file stored in my own server in this way - I'm using SwiftyJSON: func queryData(_ fileName:String) { guard let url = URL(string: JSON_PATH + fileName + ".json") else {return} // JSON_PATH +…
Frank Eno
  • 2,581
  • 2
  • 31
  • 54
1
vote
0 answers

How to handle network connection when calling API constantly at specific time interval in iOS?

I have to call API every second to get updated values. But I have some question regarding best practices to handle this Do I need to stop the timer if the internet connection is OFF? If #1 yes then is it necessary to start API call automatically or…
Nick
  • 1,127
  • 2
  • 15
  • 40
1
vote
1 answer

iOS: Code Status 400 when calling https://api.dropboxapi.com/2/users/get_current_account with the good Authorization

I tried to call the dropbox url https://api.dropboxapi.com/2/users/get_current_account to check if the token access is good. It works like a charm on Postman, but it's not working on iOS. Here is the post man call: In the Headers: In the…
ΩlostA
  • 2,501
  • 5
  • 27
  • 63
1
vote
1 answer

Is there a way to request multiple distinct resources in parallel using URLSession.shared.dataTask

I found this piece of code here on how to download images simultaneously without any breakages, func loadImageRobsAnswer(with urlString: String?) { // cancel prior task, if any weak var oldTask = currentTask currentTask = nil …
BigFire
  • 317
  • 1
  • 4
  • 17
1
vote
1 answer

URLSessionDataTask ignores URLRequest's httpMethod property

I'm having this bizarre problem in which I cannot do a simple POST request to a REST service I do not control based on GraphQL. The problem is that no matter what I set in the httpMethod property of the URLRequest class, it always uses GET…
Andy Ibanez
  • 12,104
  • 9
  • 65
  • 100
1
vote
1 answer

iOS: Data from URLSession.shared.dataTask(with: url is always nil (display 0 bytes bug in xcode debugger?)

I tried that code found on the web, but data is always nil. But when I tap it in safari, I can see a result... let urlStr = "https://gmxx2.x.frxx.com:x/xxx/xxx/FR&174" let url = URL(string: urlStr) URLSession.shared.dataTask(with:…
ΩlostA
  • 2,501
  • 5
  • 27
  • 63
1
vote
0 answers

NSURLSessionDataTask returning nil value after getting response

I created this api endpoint that sends back data about a person, and I'm trying to reach that endpoint from my app. I was able to connect to the endpoint but after calling that method it returns nil. I've attempted to use a block statement to…
1
vote
1 answer

0 bytes of data from HTTPS URLSession.dataTask

I'm trying to retrieve some JSON data from a URL, however it is returning 0 bytes every time in the data. I've checked several different SO posts, and none seem to match the exact problem I am having as the server I am getting data from indeed uses…
tayoung
  • 411
  • 1
  • 4
  • 16