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
1 answer

WebSocket in Background transfer and NSURLSession in Xamarin.iOS

I am looking into creating a Xamarin.iOS app that can connect to a WebSocket server when the app is backgrounded or suspended. The app is expected to close the channel once it receives a certain 'close' message from the server. As per Apple's…
0
votes
1 answer

I added a cookie to my URLSession, but it's missing in my URLRequest

I'm stuck on an issue with cookies in a URLSession URLRequest. I have a Swift Playground where I add a cookie to my URLSession, and I expect to see it in the request to my local server, but it's not there. What am I missing? Here is my…
Eugene
  • 3,417
  • 5
  • 25
  • 49
0
votes
1 answer

`URLSessionDelegate` methods are not called

Please, note that I've checked previous answers and I am not using callbacks in the code. In this case the delegate methods should be called Environment iOS 14.4.2 URL is valid. File is downloaded. Just the delegate not get called. The example code…
fewlinesofcode
  • 3,007
  • 1
  • 13
  • 30
0
votes
0 answers

Do authentication challenge NSURLAuthenticationMethodClientCertificate with crt and pem

I need to implement authentication challenge on iOS 14, I was given a crt and a private key in form of a pem file. I do know how to create a SecKey and SecCertificate out of it, but for the challenge I need an SecIdentity: public init(identity:…
swalkner
  • 16,679
  • 31
  • 123
  • 210
0
votes
0 answers

File download sometimes restart from the beginning when network has changed(AFURLSessionManager)

I'm having trouble with file download. My app is using AFURLSessionManager and make NSURLDownloadSessionTask by (NSURLSessionDownloadTask *)downloadTaskWithRequest:progress:destination:completionHandler:. NSURLSessionDownloadTask *task =…
Justin.Shim
  • 317
  • 2
  • 14
0
votes
1 answer

Swift: Unable to do multiple images upload using URLSession

I am trying to upload multiple images to server via MultipartFormData I had read many links, but couldn't solve mine. Code is working when we are uploading single file either .jpg or .png. In Postman multiple images are uploaded successfully. Core…
McDonal_11
  • 3,935
  • 6
  • 24
  • 55
0
votes
1 answer

NSUrlSession reset(completionHandler:)

What happens to the current tasks present in the session when we do reset(completionHandler:) on UrlSession. Also if it cancels the current tasks then how do we wait for the completion of the current tasks before calling reset(completionHandler:)
mango
  • 9
  • 2
0
votes
1 answer

How to make serial queue for a few URLSession.DataTaskPublisher?

I have several datataskpublisher, which performs requests to the server, from different application screens. How to make them run serial? Below will be a rough example This is a service that performs requests and additional logic. class Service { …
0
votes
1 answer

How to pass URLSessionTask as a parameter

I have a cell and I'm using URLSessionTask inside of it for some images. When the cell scrolls off of the screen, in prepareForReuse I cancel the task and everything works fine. Because I'm doing several thing with the image once I get it from the…
Lance Samaria
  • 17,576
  • 18
  • 108
  • 256
0
votes
1 answer

tableviewController pagination retrieved my data from server twice and not all data Is retrieved from the server

I have a tableviewController with 3 cells one for getting image and text from the server and the second for getting only text and the third one for implementing pagination with activity indicator like below in this image the 3 cells image and this…
0
votes
1 answer

Why does this website fail to convert to UTF8 in a Swift URLSession?

The following code fails: let url = URL(string: "https://www.cardboardconnection.com/1987-topps-baseball-cards")! var request = URLRequest(url: url) request.setValue("text/html; charset=utf-8", forHTTPHeaderField:…
Ethan Allen
  • 14,425
  • 24
  • 101
  • 194
0
votes
1 answer

How to download a .zip file in Swift without NSURLSession?

I'm trying to download a zip file to the user's phone storage in an iOS app. Is it possible to do this without NSURLSession?
Adrienne
  • 2,540
  • 1
  • 29
  • 39
0
votes
1 answer

Background URLSession stuck

I'm uploading a lot of files to a server using URLSession, because the uploaded files can be big I'm using URLSessionConfiguration.background so that my uploads can continue in the background. My url session is declared like…
Philou
  • 67
  • 1
  • 10
0
votes
1 answer

macOS FTP app using NSURLSession for dataTask is not working

I'm using the following code to get a directory listing for an ftp app. It works as expected in iOS, but in macOS, I get no results - data.length is always 0 - and no errors. I've also tried using Session and Task delegates, but get the same…
0
votes
3 answers

Is it possible to upload audio file to server using put request (Not multipart request) in iOS Swift

I need to upload audio file recorded in iOS device to server using PUT method in request. Now, I am confused that is it possible to upload audio file to server without multipart request in iOS Swift.
1 2 3
99
100