Questions tagged [nsurlsession]

NSURLSession is the API for HTTP connections introduced in iOS 7 and OS X 10.9.

The class NSURLSession was introduced to Apple's Foundation.framework in iOS 7 and OS X 10.9.

A NSURLSession object can be considered a group of related data transfer tasks. A response may be received and can be handled via a block statement or delegate methods. NSURLSession provides status and progress properties, of which support canceling, resuming, or suspending tasks, and resuming suspended, canceled, or failed downloads.


Types of Sessions

NSURLSession can support three different types of sessions, which is determined by the configuration object used to initialize the session object.

  • Default Sessions
  • Ephemeral Sessions
  • Background Sessions

Types of Tasks

There are three types of tasks, the last two (Download & Upload) of which support background use.

  • Data Tasks - Send and receive data via a NSData object
  • Download Tasks - Retrieves data in the form of a file
  • Upload Tasks - Sends data, most typically in the form of a file

Related tags to explore:

Adapted from Apple's URL Loading System Programming Guide > NSURLSession.

2479 questions
0
votes
0 answers

Swift URLSession returns incorrect amount of bytes on request

I have a url session requesting data by URL. The issue is the data retrieved by the url on a fresh app open is not proper. Problem: For example I delete the app and re-download the app and make a request by URL (1st time): Status Code: 200 Bytes:…
0
votes
0 answers

URLSession.didReceiveChallenge : how to ignore one specific certificate check on server-side authentication

I'm using macOS native framework to sent https requests (nsurlsession). In order to handle TLS flows of server-side authentication, I've implemented the didReceiveChallenge callback. In my special case, My https request's URL composed of IP instead…
Zohar81
  • 4,554
  • 5
  • 29
  • 82
0
votes
1 answer

Swift - How to make sure app is continue fetching data in background?

I have an iOS application where the user can trigger a lengthy update process by tapping on a button. The update process involves making API calls that can take a few minutes to complete. Everything works fine when the user stays in the foreground,…
Mahdi
  • 31
  • 1
  • 5
0
votes
0 answers

How to send image to server in post request?

Well, i need to send path of photo file, but i always have Fatal error: Unexpectedly found nil while unwrapping an Optional value. Here what a post request looks like: let parameters = [ [ "key": "description", "value": "Hello", …
0
votes
0 answers

How to correctly make post request

I need to make post request with my data. Also it takes access_token in header. Now I will describe the complete structure of my post-request in body. I have to send description which takes String. The data to be sent is taken from the…
0
votes
0 answers

NSURLSessionWebSocketTask return Bad Address error

We receive bad address error Error:(kNWErrorDomainPOSIX 错误 14 - Bad address),未能完成该操作。 Translated:(kNWErrorDomainPOSIX error 14 - Bad address),The Operation Can't Be Completed. Environment: iPhone 8#iOS#13.6# from completion handler…
Kam
  • 51
  • 6
0
votes
1 answer

iOS URLSession delegate method (session, dataTask, willCacheResponse, proposedResponse) not called

I need the API responses to be cached for a longer duration. Hence, I am trying to modify the 'max-age' header for the API response. But the urlSession(_ session: URLSession, dataTask: URLSessionDataTask, willCacheResponse…
7vikram7
  • 2,764
  • 1
  • 25
  • 43
0
votes
1 answer

URLSession mysteriously fails on cell network only

Call made like this let jsonData = try JSONSerialization.data(withJSONObject: requestBody) var request = URLRequest(url: url) request.httpMethod = "POST" request.setValue("application/json", forHTTPHeaderField: "Content-Type") request.httpBody =…
erotsppa
  • 14,248
  • 33
  • 123
  • 181
0
votes
0 answers

POST NSData to a Server

I am trying to POST the iPhone depth data to a Macbook using wifi (at-least 30 fps). I extracted depth CVPixelBuffer from ARSession followed by creating an NSMutableData. My question is that how I can POST this message (NSMutableData) to a server?…
0
votes
0 answers

How to proxy one URLSession through another URLSession?

The goal is to get one URLSession to send request not directly to the network but to another URLSession. I need the default URLSession caching mechanism but want to get modified data in some cases (particularly I want to resize some images and let…
bodich
  • 1,708
  • 12
  • 31
0
votes
2 answers

URLSession concurrency issue for async calls

I am trying to implement upload mechanism for my application. However, I have a concurrency issue I couldn't resolve. I sent my requests using async/await with following code. In my application UploadService is creating every time an event is fired…
atalayasa
  • 3,310
  • 25
  • 42
0
votes
1 answer

How to share cookies between WebView and NSURLConnection?

Currently my non-visual crawl is built using NSUrlConnection. (I need to rewrite that to NSURlSession at some point.) My visual crawl/perform-login is built using WebView. (I am working on implementing support for WkWebView, but using Lazarus so a…
Tom
  • 3,587
  • 9
  • 69
  • 124
0
votes
1 answer

how to not get empty array in swift playground?

I'm getting response from API's but I am not able to get emails array back, what am I doing wrong? I tried to add DispatchQueue.main.asyn { emails.append(result.data.email) } but its the same result. // MARK: - Response Class struct Response:…
nitpaxy
  • 67
  • 10
0
votes
1 answer

NSURLSessionConfiguration and timeoutIntervalForResource for NSURLSessionDelegate didCompleteWithError

Wondering if someone can provide their two cents. Below code successfully triggers didCompleteWithError NSURLSessionDelegate method upon timeoutIntervalForResource timeout. NSURLSessionConfiguration *config = [NSURLSessionConfiguration…
0
votes
0 answers

NSUrlSessionTaskDelegate DidSendBodyData totalBytesSent inaccurate

NSUrlSessionTaskDelegate DidSendBodyData totalBytesSent seems to indicate that upload progress is being reported out of order. I created a simple test with a single upload, and logged the value of totalBytesSent every time it was called. For…
Magnetic Llama
  • 154
  • 2
  • 11