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

NSURLSession with a performSelector:

I found out that iOS can run processes even when your application is in background mode (minimized) in at most 10 minutes, and to work around that and make it run forever, it would be necessary: Apps that need to download and process new content…
LettersBa
  • 747
  • 1
  • 8
  • 27
1
vote
1 answer

NSURLSessionUploadTask returns HTTP 403 Error Page

I've facing a pretty odd issue. I'm attempting to upload an image to a PHP script. The build compiles without errors, which is what I had expected, but when the session is actually completed, it returns with an HTTP error 403. I'm aware that 403 is…
Jeffrey
  • 1,271
  • 2
  • 15
  • 31
1
vote
1 answer

How to use specific network connection with NSURLSession (OS X)

Cannot find NSURLSessionConfiguration property to select certain network connection (wired, wi-fi etc.) NSURLSession to work with. Already got current interfaces list (with ifaddrs struct), now I need to figure out, how to use this data by…
Daniyar
  • 2,975
  • 2
  • 26
  • 39
1
vote
1 answer

How to make sure NSUrlSession does not fetch cached pages?

I'm using NSUrlSession to download the contents of an HTML page (so I can parse it, against my will). My problem is that iOS seems to be caching the page with my app, so that even if I update this page on the server, my app keeps seeing the old…
MusiGenesis
  • 74,184
  • 40
  • 190
  • 334
1
vote
2 answers

Background Upload With Stream Request Using NSUrlSession in iOS8

Previously in iOS7 when we try to upload with stream request in background we get following exception Terminating app due to uncaught exception 'NSGenericException', reason: 'Upload tasks in background sessions must be from a file' But in iOS8 there…
1
vote
0 answers

Xcode indicates that nsurlsessiondownloadtask consumes massive amounts of memory

I am using NSUrlSession and NSUrlSessionDownloadTask to download files from a server to my app. When I am running my app written in Swift from Xcode and looking at the memory consumption gauge the memory consumed increases steadily as the files are…
1
vote
1 answer

NSURLSession dataTaskWithRequest time

let task = NSURLSession.sharedSession().dataTaskWithRequest(request) { data, response, error in var taskString = NSString(data: data, encoding: NSUTF8StringEncoding) println(taskString) …
Saber
  • 49
  • 3
  • 5
1
vote
1 answer

UIImagePNGRepresentation causes HTTP error 403

I've got a pretty particular issue today. I've created a multipart/form-data header in iOS, which is then sent to a PHP script on my web server. It works fine with only strings as data, but when I attempt to append an image to the header, it returns…
Jeffrey
  • 1,271
  • 2
  • 15
  • 31
1
vote
1 answer

Freesound OAuth2 authentication fails

I'm trying to create an iOS app that uses OAuth2 authentication using the native iOS NSURLSession URL loading classes. I gain an access token fine using the directions here: http://www.freesound.org/docs/api/authentication.html I subsequently…
Remover
  • 1,616
  • 1
  • 17
  • 27
1
vote
0 answers

How to use ReactiveCocoa to subscribe to multiple selectors only once for each downloaded file

I am new to ReactiveCocoa and trying to build an API Client using it. I want the RAC observer to fire once on each URLSession:downloadTask:didFinishDownloadingToURL: delegate callback. as my code is now it will create an observer for each file that…
bogen
  • 9,954
  • 9
  • 50
  • 89
1
vote
0 answers

How to convert cURL form login code to Swift

I am trying to login (form) into a website and parse data with Swift and NSURLSession. I have been using cURL to confirm that this is actually possible, and the following code returns the webpage-body as expected. curl -c cookie.txt -d…
Karl Ivar
  • 287
  • 1
  • 3
  • 6
1
vote
0 answers

How to save uploaded image from iOS to disk from PHP?

I've recently been attempting to send an image from iOS to a PHP file, then save said image to the disk and add the path to the database. I believe that my NSURLSession for uploading the image to the PHP file is working, but don't hold me to that,…
Jeffrey
  • 1,271
  • 2
  • 15
  • 31
1
vote
0 answers

NSURLErrorDomain error -1001

I'm a little bit baffled by this one - I have been developing an app on my iPhone 4 and I just got an iPhone 5...I am now using the iPhone 5 to develop (for obvious reasons). When I was developing on my iPhone 4 all of my NSURLSession code worked…
ewizard
  • 2,801
  • 4
  • 52
  • 110
1
vote
0 answers

NSURLSession file transfer restarted?

I am using NSURLSession for uploading a file with background transfer service, but after uploading few bytes. NSURLSession starts upload again, Don't know exactly why NSURLSession restart and send the same bytes to the server which are already…
1
vote
0 answers

NSURLSession Crash swift iOS 7

I have a function to retrieve data from an API using an URL link. Everything works on iOS 8 but when I run it on a device with iOS 7, the following bit of swift code fails and the app crashes - the last line (when setting the session…
sachalondon
  • 165
  • 1
  • 11