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.

2431 questions
32
votes
2 answers

NSURLSession + server with self signed cert

I have an app that is production along with a development server that has a self signed certificate. I am attempting to test NSURLSession and background downloading but can't seem to get past - (void)URLSession:(NSURLSession *)session…
random
  • 8,428
  • 12
  • 46
  • 81
31
votes
5 answers

How To Download Multiple Files Sequentially using NSURLSession downloadTask in Swift

I have an app that has to download multiple large files. I want it to download each file one by one sequentially instead of concurrently. When it runs concurrently the app gets overloaded and crashes. So. Im trying to wrap a downloadTaskWithURL…
CraigH
  • 1,817
  • 3
  • 26
  • 43
31
votes
2 answers

Set number of concurrent downloads with NSURLSessionDownloadTask

I'm using the new NSURLSession API and allowing the user to download files. I'd like to try and tell my NSURLSession how many simultaneous downloads to run, but I don't see a way to do it. I'd like to try to avoid managing the download tasks myself,…
Cory Imdieke
  • 12,771
  • 8
  • 34
  • 46
30
votes
2 answers

NSURLSession causing EXC_BAD_ACCESS

I've noticed that implementing NSURLSessionDataDelegate and starting a task will very occasionally throw an EXC_BAD_ACCESS. The actual calling method that gives the error seems to vary but always comes from CFNetwork. For the most part, the calling…
oliveroneill
  • 858
  • 9
  • 13
30
votes
3 answers

Using NSURLSession from a Swift command line program

I'm trying to test a little proof-of-concept command line app prior to integrating it into a larger app. What I'm trying to do is download some data using NSURLSession using this example. However it appears that if I use the examples given in a…
Friedrich 'Fred' Clausen
  • 2,931
  • 5
  • 33
  • 59
29
votes
5 answers

What is difference between NSURLSessionDataTask vs NSURLSessionDownloadTask

In latest apple introduce new NSURLSession in replace of NSURLConnection, so in there are different task , so what is the difference between NSURLSessionDataTask, NSURLSessionDownloadTask ? and in which scenario use NSURLSessionTask and where…
28
votes
5 answers

How to get cookie from a NSURLSession with Swift?

I have a NSURLSession that calls dataTaskWithRequest in order to send a POST request in this way func makeRequest(parameters: String, url:String){ var postData:NSData = parameters.dataUsingEncoding(NSASCIIStringEncoding)! var…
Jorge Casariego
  • 20,634
  • 6
  • 84
  • 96
28
votes
4 answers

Showing the file download progress with NSURLSessionDataTask

I want to display file download progress (how many bytes are received) of particular file. It works fine with the NSURLSessionDownloadTask .My question is I want to achieve the same with the NSURLSessionDataTask. Here is the code which receives file…
27
votes
7 answers

How to make NSURLSession POST request in Swift

Hi I am very beginner for Swift and I am trying to make NSURLSession "Post" request sending some parameter like my below code According to my below code response not coming from server can some one help me please BackGroundClass:- import…
Krish
  • 3,668
  • 10
  • 46
  • 86
27
votes
2 answers

iOS 9: Crash on -[_NSXPCDistantObject methodSignatureForSelector:]

I'm getting a strange bug: Fatal Exception: NSInvalidArgumentException *** -[_NSXPCDistantObject methodSignatureForSelector:]: No protocol has been set on connection connection to service named com.apple.nsurlsessiond" This issue only…
bcattle
  • 10,155
  • 5
  • 54
  • 73
27
votes
3 answers

What is the biggest difference between NSURLConnection and NSURLSession

NSURLSession is new network SDK than NSURLConnection from Apple. 3rd old choice is CFNetwork. Question here is to figure out the biggest difference between them to understand why Apple is evolving like these. Thanks
Forrest
  • 101,971
  • 19
  • 69
  • 107
26
votes
4 answers

NSURLSession/NSURLConnection HTTP load failed (kCFStreamErrorDomainSSL, -9813) in iOS 9 with Xcode 7.1

I am using iOS 9 as target & using Xcode 7.1, tried everything as my level best for all the solutions of ATS but didn't work. Below is the following error description coming at console. If any suggestion comes I will be obliged. Some of the key…
SAYAN NANDY
  • 273
  • 1
  • 3
  • 8
26
votes
2 answers

How can I get the Data from NSURLSession.sharedSession().dataTaskWithRequest

class PostFOrData { let url = NSURL( string: "http://210.61.209.194:8088/SmarttvWebServiceTopmsoApi/GetReadlist") var picUrl = NSURL(string : "http://210.61.209.194:8088/SmarttvMedia/img/epi00001.png") var responseString : NSString =…
Liang
  • 261
  • 1
  • 3
  • 5
26
votes
3 answers

How to cache using NSURLSession and NSURLCache. Not working

I have a test app setup and it successfully downloads content from the network even if the user switches apps while a download is in progress. Great, now I have background downloads in place. Now I want to add caching. There is no point to me…
John Erck
  • 9,102
  • 5
  • 55
  • 71
25
votes
5 answers

what is the advantage of using Alamofire over NSURLSession/NSURLConnection for networking?

Can anyone help me in understanding these question : What is the advantage of using Alamofire over NSURLSession/ NSURLConnection? What are the differences between NSURLSession and NSURLConnection?