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

Uploading file using NSURLSessionUploadTask to PHP server

I have a video upload system in an iOS app using NSURLSessionUploadTask. The video file is saved to an NSURL so I am using the following code in my upload method: request.HTTPMethod = @"POST"; [request addValue:@"file"…
GTF
  • 8,031
  • 5
  • 36
  • 59
1
vote
1 answer

NSURLRequest HTTPBody is null

I've been trying to send POST requests to a server (which I know works from using Postman) using NSURLSession. I create a request as follows: NSMutableURLRequest *request = [self createRequestWithPath:[self getPathForEndpoint:endpoint]]; [request…
GTF
  • 8,031
  • 5
  • 36
  • 59
1
vote
0 answers

NSURLProtocol + WebView = Not able to get Data of HTTP post

I have created a scaled down version of my own browser using WebView + NSURLProtocol. I took the sample code from following blog to get started. http://www.raywenderlich.com/59982/nsurlprotocol-tutorial ( To download the code, go to heading "Where…
iOSMonkey
  • 119
  • 1
  • 1
  • 9
1
vote
2 answers

NSURLSession dataTaskWithRequest Swift

I have the following code: var resultData:NSData? task = session!.dataTaskWithRequest(request) { (data: NSData!, response: NSURLResponse!, error: NSError!) in if ((error) != nil) { println("Error") return } resultData…
Bella Yordanova
  • 133
  • 1
  • 6
1
vote
1 answer

sessionWithConfiguration freezing iOS 8 iPhone 4S on new Xcode 6.0.1

I am experiencing a disturbing issue when trying to execute one of my apps on an iPhone 4S with iOS8 and Xcode 6.0.1. What happens is that the control seems to freeze in the last instruction of the block: dispatch_once(&onceToken, ^{ …
Fabrizio Bartolomucci
  • 4,948
  • 8
  • 43
  • 75
1
vote
3 answers

Send UIImage POST to server from UIImagePickerController?

I am trying to send a UIImage take with the UIImagePickerController to a server POST along with other pertinent values. But I get at the line that tries to set the dictionary value @"image" to UIImageJPEGRepresentation(image,…
izk
  • 1,189
  • 2
  • 8
  • 23
1
vote
0 answers

How can I send POST data using NSURLSession using Swift?

I found this good answer about how to make a HTTP request, I am using the next code let url = NSURL(string: "http://www.myserver.com") let task = NSURLSession.sharedSession().dataTaskWithURL(url) {(data, response, error) in …
Fernando Santiago
  • 2,128
  • 10
  • 44
  • 75
1
vote
3 answers

read online JSON file in swift

I am trying to read an online JSON file using the sample found here. It seems quite straight forward except when I run it. It keeps failing at dataTaskWithURL call and the error.localizedDescription is "The operation couldn't be completed.…
Reza Jooyandeh
  • 761
  • 5
  • 19
1
vote
0 answers

NSURLSession + HTTPS is any other setup needed?

I'm sending with POST some data to server using NSURLSession, I did it over HTTP, now I had to change to HTTPS. To my pleasant surprise all is working fine, which means that all I did was changing url from http to https. But is it enough? Should I…
Lukasz 'Severiaan' Grela
  • 6,078
  • 7
  • 43
  • 79
1
vote
2 answers

NSURLCredentialStorage default credential not used automatically

I'm switching from NSURLConnection to NSURLSession for my app communications and, while I'm at it, trying to move from delegated authentication to utilising NSURLCredentialStorage. I've moved over the code however I'm getting…
Red Nightingale
  • 669
  • 3
  • 19
1
vote
0 answers

Handle backgroundSession with NSURLSession in Swift

backgroundSession is not working well with my app the download sometime stop and sometime done but the file saving fails here is the code i am using just converted it today into swift but i am not sure if it's right * AppDelegate * var…
Amr Mohamed
  • 2,290
  • 4
  • 20
  • 39
1
vote
1 answer

Downloading files into root app directory using Swift

I'm new to coding for Swift and I don't have much experience of Objective C so am trying to download a file from the web (csv) and dump it into the root program directory. Unfortunately I can't find any how-to tutorial in Swift although I am working…
Oliver Spencer
  • 2,021
  • 3
  • 16
  • 22
1
vote
1 answer

Is uploading a file using a download task for background transfert a good thing?

I need to upload files in background for my application. So i looked uploadtask method but it actually need a fileurl to work with background transfert. It won't really be a big deal to put my object in JSON/XML and save it as a file but it would…
1
vote
1 answer

NSURLSession send GET request even if I set POST in HTTPMethod

i'm trying to send a POST request to my server with the following code: NSURLSessionConfiguration *defaultConfigObj = [NSURLSessionConfiguration defaultSessionConfiguration]; NSURLSession *defaultSession = [NSURLSession…
jrg
  • 63
  • 1
  • 5
1
vote
0 answers

Fire and forget URL download for iOS

Problem I'm currently grabbing weather forecast information with [NSData dataWithContentsOfURL: url]. The problem with this is that if there are errors during the URL fetch, I just get back a nil. An alternative to the method [NSData…
Benjohn
  • 13,228
  • 9
  • 65
  • 127