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

Swift dataTaskWithRequest completion block not executed

I have a function which posts a dictionary back to the server and return the status code or error content when there's an error. It works fine sometimes, while the rest of the time the completion section is skipped. func postData(url: String, query:…
whitney13625
  • 583
  • 1
  • 9
  • 28
1
vote
0 answers

Using NSURLSession in a synchronous loop

I have a program that processes input, one record at a time. For each record it does an HTTP POST to look up some information (based on the contents of that record) and it wants to append at the end of the record some of the information it received…
1
vote
0 answers

AFNetworking, background downloads and watchdog timer

I'm using AFNetworking 2.5.2, and I have successfully implemented the usage of AFURLSession to handle background downloads. The issue is the following: The downloads can be very small (a few Kbs) or quite large (more than 30 or 50 Mbs). These…
thomzon
  • 11
  • 2
1
vote
0 answers

swift constant implicitly unwrapped optional properties cant't be initialised

Here is my simple swift class: class SessionInitTest: NSObject, NSURLSessionDataDelegate { let session: NSURLSession! override init() { super.init() session = NSURLSession(configuration: nil, delegate: self, delegateQueue:…
D.Young
  • 113
  • 1
  • 7
1
vote
2 answers

Download delegates with NSURLSession (IOS, swift)

I try to download a file in swift using NSURLSession: My delegates are never called and I don't know why. Can somebody help ? Code: My Class has following protocols: class ViewController: UIViewController, NSURLSessionDelegate { In my Class I have…
mcfly soft
  • 11,289
  • 26
  • 98
  • 202
1
vote
2 answers

NSURLSession dataTaskWithRequest progress tracking

Im using NSURLSession dataTask with NSOoperationQueue to download a file with multiple connections for faster speed. Creating operations from NSURLSession and passing them to OperationQueue. Now my struggle here is, as i see in apple docs, only…
user2125726
  • 127
  • 2
  • 10
1
vote
2 answers

Upload iOS Image to PHP Web Page Using NSURLSession

Brand new to iOS development, so I'm feeling a little lost here. How can we use NSURLSession to upload an image to a web server (a PHP rest API that I'll setup)? I've already been able to write the code to the point where a user is able to select…
pwoerfulafhjksdh
  • 381
  • 1
  • 3
  • 11
1
vote
1 answer

NSURL returning nil for certain cases

I'm creating an NSURL to send as a request to a PHP rest API that I've got setup. Here's my code below: NSMutableString *url = [NSMutableString…
pwoerfulafhjksdh
  • 381
  • 1
  • 3
  • 11
1
vote
2 answers

NSURLSession - use uploadTaskWithStreamedRequest with AWS IOS SDK

I've searched for days for a way to upload an IOS asset without creating a copy of the file in temp directory without luck. I got the code working with a temp copy but copying a video file that could be anywhere from 10MB to 4GB is not realistic. …
jt_dylan
  • 71
  • 1
  • 6
1
vote
1 answer

Response Headers and URL in AFNetworking

I am using AFNetworking to upload video and Image to a server. NSMutableURLRequest *request = [[AFHTTPRequestSerializer serializer] multipartFormRequestWithMethod:@"POST" URLString:urlString parameters:dictParams…
channi
  • 1,028
  • 9
  • 16
1
vote
0 answers

NSURLSession didBecomeInvalid usage

Apple's docs on NSURLSession state that you have to explicitly invalidate your session so it releases its strong delegate reference, or else you leak memory. So I'm calling finishTasksAndInvalidate in didCompleteWithError. Should I also invalidate…
Tom Hamming
  • 10,577
  • 11
  • 71
  • 145
1
vote
1 answer

Buggy and Slow scrolling when loading TableView images from CoreData

Problem : The process of loading images to Table View using their Paths that who stored in Core Data DB works fine , but the user experience not going well. The scroll is slow and buggy. Importants Notes : For my local DB i use Core Data Im not…
1
vote
1 answer

Autocomplete with NSURLSession doesn't work well with slow internet connection

I have a searchBar. When you type in the searchBar(at least 3 character) a request with the searchString is sent to a server. This server response with a XML. This XML is parsed. A list is displayed to the user. Each time the user type in the…
Superolo
  • 98
  • 6
1
vote
1 answer

URLSession configuration's header setting only work for PUT, not for POST

I'm working with NSURLSession default session with the following code var defaultSession : NSURLSession { var config = NSURLSessionConfiguration.defaultSessionConfiguration() config.HTTPAdditionalHeaders = [ // FIXME: for POST this…
bolerovt
  • 623
  • 7
  • 18
1
vote
1 answer

Loading file from Directory to UIIMAGE doesnt work

So i'm downloading an image using DownloadTask , and than save the image in the Cache Directory with name for my own uses : let fileManager = NSFileManager.defaultManager() let documents =…