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
2 answers

How to use OperationQueue to handle URLSessions for an image downloader

I'm trying to create a simple ImageDownloader framework in swift. What I'd like to achieve: Able to download images with given URLs Cache with url string So fetching just one image is no problem, I just used func dataTask(with url: URL,…
RobotX
  • 208
  • 2
  • 15
0
votes
0 answers

NSURLSessionDataTask completionHandler no longer executes when I switch to Release build configuration

I built a simple command line tool that fetches some data using an NSURLSessionDataTask. Now that I'm done coding, I find that the executable hangs when I switch to the Release build configuration in Xcode. I'm using a while loop that waits for the…
0
votes
0 answers

urlSession didSendBodyData reports wrong totalBytesExpectedToSend

The didSendBodyData method of URLSession delegate with uploadTask running is called with a wrong totalBytesExpectedToSend value. It seems to be about double of what it should be but not exactly. The URLSessionTask parameter contains field…
jab11
  • 867
  • 1
  • 8
  • 15
0
votes
2 answers

Using Swift with URLSession works with GET and PUT, but it gives error 405 Method Not Allowed when I use POST

I develop an iOS app using Swift. I use the following method below to access an login ENDPOINT with PUT method. let loginData = LoginModel("myUser","myPassword") var loginClassJson:Data? do{ loginClassJson = try…
fabiobh
  • 705
  • 2
  • 13
  • 33
0
votes
0 answers

alternatives for tlsMinimumSupportedProtocolVersion in iOS 12

My iOS library (a dynamic xcFramework) uses URLSession to perform some networking tasks. It targets iOS 13 and higher. I set configuration.tlsMinimumSupportedProtocolVersion = tls_protocol_version_t.TLSv13 to mitigate outdated TLS attacks. So far…
Alex Cohn
  • 56,089
  • 9
  • 113
  • 307
0
votes
1 answer

URLSession returns the size of the data instead of the actual contents of the data

I'm trying to learn how to use URLSession, so I'm trying to get the raw JSON from a URL as a consistency check that it worked. But I don't understand why it's outputting the data responses size in bytes instead of the actual data Here's an example…
0
votes
0 answers

Add image url parsed from JSON API into UIImageView

I've parsed JSON API file into swift for nowplaying data of my radio. Now I'm able to display artist and song title in the two labels (Still looking how to fetch new data from API, when new song is playing - now the app shows static artist and…
LewTrocki
  • 41
  • 7
0
votes
1 answer

NSURLSession Error Domain=NSPOSIXErrorDomain Code=28 "No space left on device"

we use single NSURLSession download remote image from network. But we got strange error log that somebody cannot show image because got error Error Domain=NSPOSIXErrorDomain Code=28 "No space left on device" This error happens rarely and cannot…
qing
  • 21
  • 3
0
votes
1 answer

Handle Timeout in Alamofire

I want to handle timeout error with Alamofire as follow. User initiate request with button press If timeout occurs then it will display message with custom view with 2 buttons (cancel & retry) if user presses retry_button the request should…
nirav
  • 573
  • 5
  • 20
0
votes
0 answers

How to make HTTP Get request objective-c

I have a host where going my key and hid check. Host is showing there are no any requests. NSMutableURLRequest *request = [[NSMutableURLRequest alloc] init]; [request setURL:[NSURL…
0
votes
1 answer

NSURLSession post a param which has a url encode string

I need to use NSURLSession send a post request to server.and one of the params need to be a url encode string.I found in Charles it is not I expected format. Here is the code. NSMutableDictionary *md = [self defaultParams].mutableCopy; [md…
childrenOurFuture
  • 1,889
  • 2
  • 14
  • 23
0
votes
1 answer

NSURLSession: method dataTaskWithRequest never reach completion callback on lengthy responses

The following code that used to create communication session with a remote server and send/receive HTTP requests/responses. However, when a large file is attached to the response, the callback block never reached. Only when explicitly invoke the…
Zohar81
  • 4,554
  • 5
  • 29
  • 82
0
votes
1 answer

Request NSURLSession with SSL .cert and .key files

I have to login via https in an Obj-C project. Everything is fine with all the url, the user, pass and the needed stuff. For identify, the server checks by ssl .cert and .key files. So far, so good, the files were uploaded to the server, and the…
szvarga
  • 3
  • 2
0
votes
1 answer

Refresh Bearer Token and resume current API

I need to resume my WebService if my bearer token expire by http code 401 , below is my code. When a 401 error occurs that means the Access Token has expired and I need to send a Refresh Token over to my server to obtain a new Access Token. After…
9to5ios
  • 5,319
  • 2
  • 37
  • 65
0
votes
1 answer

Got 401 to try request login from URLSession

I have this method func loginUser(for email: String, password: String, completed: @escaping (Result) -> Void) { let endpoint = baseURL + "login" guard let url = URL(string: endpoint) else { …
Josué H.
  • 1,171
  • 3
  • 15
  • 35