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
1
vote
0 answers

NSurlsession in nsobject Delegate Issues

Hello i am facing a Small Problem with usurlsession. here is my code NSURLSessionConfiguration *defaultConfigObject = [NSURLSessionConfiguration defaultSessionConfiguration]; NSURLSession *defaultSession = [NSURLSession sessionWithConfiguration:…
akshat
  • 59
  • 3
1
vote
1 answer

0_ os_lock_corruption_abort in NSURLProtocol

I've built a custom NSURLProtocol which is used by a WebView whilst it browses. But at seemingly random times (between a 20 seconds or a few minutes into browsing) I am getting an EXC_BREAKPOINT and the app stops running in my NSURLProtocol. The…
Sam Heather
  • 1,493
  • 3
  • 19
  • 42
1
vote
2 answers

NSURLSession to perform upload task as 'curl'

This is the curl command i use to upload PDF's and it works perfectly: curl -u USERNAME:PASSWORD -T MyPDF.pdf —url https://mywebserver.com I am using NSURLSession and upload task with delegates but my PDF is never uploaded. Here is my code: -…
1
vote
1 answer

NSURLSession authentication for api

I am trying to access a web page to retrieve JSON data. When I access the page through the browser it shows me a small box said authentication required A username and password are being requested by The site says: " API"" I am trying to get these…
miss h
  • 133
  • 1
  • 2
  • 15
1
vote
1 answer

How to add data to HTTPBody with PUT method in NSURLSession?

This is my code. It's working with POST but not with PUT. let url:NSURL = NSURL(string: urlApi)! let session = NSURLSession.sharedSession() let request = NSMutableURLRequest(URL: url) request.HTTPMethod = "PUT" request.cachePolicy =…
1
vote
1 answer

This application is modifying the autolayout engine from a background thread in objective c

I am getting weird crash in the my application. Mainviewcontroller.m : there is one method which call the webservice method (which is in another delegate class) and then when the response is receive the method is getting call back.…
iOS developer
  • 131
  • 1
  • 1
  • 9
1
vote
1 answer

Swift 2 How do I force Session data task to execute .resume() before continuing

I'm going to crazy trying to figure out how to prevent the rest of my code from executing before a session dataTaskWithRequest is finished. No matter what I do, the data task won't .resume() until everything else finishes. Nothing works. Not using a…
dbconfession
  • 1,147
  • 2
  • 23
  • 36
1
vote
1 answer

Threading Behaviour of NSURLSessionTasks from Multiple NSURLSessions?

Say I have 5 NSURLSessions and I create an NSURLSessionDownloadTask under each one. I then start each task running in a for loop. How does the threading behave for the request ? Are they executed async individually, or would they be processed…
1
vote
2 answers

NSMutableURLRequest setting authorization header

When setting the “Authorization” header of a NSMutableURLRequest, my server’s response of headers does not include that header: [Host] => myhost.com [Content-Type] => application/x-www-form-urlencoded [Connection] => keep-alive [Accept] =>…
Adam Carter
  • 4,741
  • 5
  • 42
  • 103
1
vote
3 answers

iOS - NSURLSessionTask unzip file downloaded

I have files download at didFinishDownloadingToURL: and I want to unzip it. My current code looks like this: - (void)URLSession:(NSURLSession *)session downloadTask:(NSURLSessionDownloadTask *)downloadTask didFinishDownloadingToURL:(NSURL…
imstillalive
  • 369
  • 4
  • 14
1
vote
1 answer

Swift: downloadTaskWithURL sometimes "succeeds" with non-nil location even though file does not exist

The downloadTaskWithURL function sometimes returns a non-nil location for a file that does not exist. There is no file at http://192.168.0.102:3000/p/1461224691.mp4 in the test environment. Most of the time, invoking downloadTaskWithURL on this URL…
Crashalot
  • 33,605
  • 61
  • 269
  • 439
1
vote
2 answers

NSURLSessionConfiguration background task on cellular Network not downloading

I am downloading a file from the web. File size is big some times may reach up to 100MBs some times, I want to continue downloading while to app goes to background or when the device is locked. For this i am using AFNetworking…
1
vote
1 answer

NSURLSession with share extension returns -995 on OSX

I'm trying to upload data using NSURLSession with a background task from an OSX share extension. As soon as I start the task, by delegate is called back with the world's least helpful error message: The operation couldn’t be completed.…
tarmes
  • 15,366
  • 10
  • 53
  • 87
1
vote
1 answer

Exact Difference between NSURLConnection and NSUrlSession?

I am new to the concept of NSURLSession. Now I am working on the sample on NSURLSession. I read so many answers about the difference between them but I didn't understand clearly.Can any one please tell me the difference between them with simple…
anusha hrithi
  • 709
  • 2
  • 9
  • 13
1
vote
1 answer

Swift NSURLSession: trouble when running multiple requests at the same time

I'm currently building a weather application where I have one container ViewController managing multiple child ViewControllers, whose main views live inside the container ViewController's UIScrollView. Each child VC has a location property, which is…
Nico
  • 194
  • 1
  • 12