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

AFNetworking -1017 error

I am working on iOS application and facing one strange issue. I am using AFNetworking framework to communicate with server (HTTPS communication). I am retrieving student data from server by using "getStudentData" web service API. It is post request.…
Swapnil
  • 1,858
  • 2
  • 22
  • 49
1
vote
1 answer

NSURLSessionTask creation fail in extension with backgroundSessionConfiguration

Context: I try to call a create a task (download or upload) from an action extension, with a backgroundSessionConfiguration. To do this I fallow the exemple in apple documention -(void)downloadTest { NSURLSession *mySession = [self…
Hikosei
  • 193
  • 1
  • 11
1
vote
2 answers

upload image files from IOS to web server

What is the best way to upload image files to web server in java considering IOS9 and swift 2. Upon searching, I realised that similar question was asked and many different methods are available online to upload images. However I am not sure on what…
PK20
  • 1,066
  • 8
  • 19
1
vote
1 answer

How to decode special characters in an NSURL in Swift?

I have a string: /?fmt=json When I create an NSURL object from the string, the URL is: /%3Ffmt=json When I send the request with this URL (using an NSURLSession), however, it gets denied access, as…
Karl Thompson
  • 65
  • 1
  • 7
1
vote
1 answer

How to download from FTP via NSURLSessionStreamTask?

Before iOS 9, I use the CFStream APIs (which are deprecated after iOS 9) to list / download / upload files via FTP. Now, I have to transfer my program to adapt iOS 9. How can I download files from FTP via NSURLSessionStreamTask?
ru1eX
  • 11
  • 1
1
vote
1 answer

NSURLSession using client SSL cert gives "Error Domain=NSURLErrorDomain Code=-999 "cancelled""

I am trying to use NSUrlsession to connect server with SSL (.p12) client certificate. I have connected to same server using NSURLConnection successfully. But with NSURLsession i get "cancelled" error. Following is my setup: -(void)…
neo
  • 169
  • 2
  • 10
1
vote
1 answer

NSURLSession, Completion Block, Swift

Im working with NSURLSession. I have an array with restaurants and i'm requesting the dishes for every restaurant in the array to the api. The dataTask works,i'm just having a real hard time trying to call a method only when the all dataTasks are…
Gama
  • 352
  • 2
  • 16
1
vote
1 answer

NSURLSession, multiple data tasks, completionHandler

I would like to use NSURLSession and dataTaskWithURL:completionHandler: to download 4 different URLs into NSData objects. I know I can call: [session dataTaskWithURL completionHandler:^(NSData* data, NSURLResponse* response, NSError* error) { //…
Trygve
  • 1,317
  • 10
  • 27
1
vote
1 answer

Loading images is slow after changing NSURLConnection to NSURLSession

I had a code in iOS 8 for loading my images, and it was quite fast. if let url = NSURL(string: urlString) { let request = NSURLRequest(URL: url) NSURLConnection.sendAsynchronousRequest(request, queue: NSOperationQueue.mainQueue()) { …
Pan Mluvčí
  • 1,242
  • 2
  • 21
  • 42
1
vote
2 answers

NSURLSession sometimes returns data but sometimes don't iOS 9 - Swift 2.0

I'm developing an application what's based on JSON objects requested from specified URL but sometimes (not every time) I get no result Gonna show some code snippets that can help determining this simple (?) problemI have an array called "Data" (var…
Szilárd Dóró
  • 93
  • 1
  • 10
1
vote
1 answer

Use Type T as parameter in completion handler

I have written a function for a URL request. This contains a completion handler that returns a dictionary of [String: AnyObject] that is fetched from the URL. The code for this is: func getDataAsyncFromURLRequest(url: NSURL, completion: ([String :…
Benjamin Hviid
  • 463
  • 2
  • 5
  • 13
1
vote
2 answers

What is the proper way to use resumeData when working with NSURLSessionDownloadTask?

I'm working on an application that download files from our server (fairly large files). I manage the download files in foreground and background (without closing the application). My problem is with the case that the user intentionally closes the…
Emil Adz
  • 40,709
  • 36
  • 140
  • 187
1
vote
1 answer

Do I have to close a connection created with NSURLSessionDataTask

I've just developed a library in Swift which is posting data to a specific server. I open the connection with NSURLSession.sharedSession().dataTaskWithRequest(request). Now I was wondering if I have to handle the closing of this connection or does…
ph1psG
  • 568
  • 5
  • 24
1
vote
1 answer

iOS Swift fastest way to download many small files

I'm writing an iPad app that needs, to download many, but fairly small, .json and .jpg files from an server. So fare I am doing it like this: ///Function to allow for recursive calls to syncronize inspections sequentially. func…
Bjqn
  • 146
  • 2
  • 19
1
vote
1 answer

AWS S3 Upload works on Simulator but not on Device

I'm encountering an interesting problem. Trying to upload a file to AWS S3, it works perfectly when run on a simulator, also when run on a connected device (DEBUG mode). But when I package the app and deploy it to a device, it doesn't work. I keep…
Rahul Jiresal
  • 1,006
  • 13
  • 24