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 Error: cannot invoke `dataWithRequest` with an argument list of type `(NSURL, completionHandler:(_,_,_) -> Void

import UIKit class ViewController: UIViewController { @IBOutlet weak var textfield: UITextField! @IBAction func whatIsThePrice(sender: AnyObject) { var url = NSURL(string: "https://uk.finance.yahoo.com/q?s=" + textfield.text +…
Alex
  • 25
  • 3
1
vote
1 answer

NSURLSession in For Loop to Download Image Data then add to NSMutableArray

My application has a UITableView with a cell that contains a UICollectionView subview (not reused). The collectionView's cells have a single UIImageView to hold a picture. I am trying to download all of the images at once, store them in an array,…
Brandon A
  • 8,153
  • 3
  • 42
  • 77
1
vote
1 answer

How to replicate Apple mail app upload que when no connection is found

If you try to send an email using the iOS mail app when your device has no connection it will que up the message to send when the device finally finds a connection, even if the app is backgrounded. You can hear that whoosh sound when it sends the…
1
vote
0 answers

Issue with NSURLSession with multiple downloads in background with multiple sessions and multiple segments

We have crated session with below configuration code. I call this method for each task I crate. +(NSURLSession ) getNewSessionWithID:(NSString )sessionID delegateObject:(id)sender { NSURLSession *session; NSURLSessionConfiguration…
The iOSDev
  • 5,237
  • 7
  • 41
  • 78
1
vote
3 answers

How can we upload multipart form data with nested JSON parameters in Swift?

I need to upload an image to the server endpoint where the structure has to be as following: { "image": { "file": imageData }, "access_token": access_token } How can I send such a request using NSURLSession (or maybe even Alamofire or…
mohonish
  • 1,396
  • 1
  • 9
  • 21
1
vote
1 answer

Use NSURLSessionDownloadTask to download only part of a file

I am trying to use NSURLSessionDownloadTask to download a large file. However, I only want to download the first 10MB of that file. I know how to cancel the operation once 10MB has been downloaded, but how do I force a call on…
etayluz
  • 15,920
  • 23
  • 106
  • 151
1
vote
1 answer

Website fetch, using NSURLSession and changing INPUT Field value on this site

I wanna fetch the content of a website. But to get the correct content, it is necessary to change a Input Html sroll field on the side? Many idea how to manage with xcode? Thanks a lot!! Lars
1
vote
1 answer

NSURLSession blocks memory management

If I would recreate NSURLSession, would I be copying the block parameter passed into this function: - - dataTaskWithRequest:(NSURLRequest *)request completionHandler:(void (^)(NSData *data, NSURLResponse *response, NSError…
1
vote
1 answer

"NSURLSession sharedSession" is not kind of NSURLSession

I created category for NSURLSession, and then I faced a problem. In iOS 7, [[NSURLSession sharedSession] isKindOfClass:[NSURLSession class]] returns NO. I know that [NSURLSession sharedSession] is returning instance of __NSCFURLSession, but it is…
Alfred Zien
  • 1,025
  • 1
  • 11
  • 31
1
vote
1 answer

Can I allow raw unicode in HTTP headers using NSUrlSession?

I'm constructing an NSUrlSession as follows: NSUrlSessionConfiguration sessionCfg = NSUrlSessionConfiguration.CreateBackgroundSessionConfiguration("mySpecialSessionName"); NSUrlSessionDelegate sessionDelegate = new MySessionDelegate(); urlSession =…
Mike Asdf
  • 2,309
  • 26
  • 34
1
vote
2 answers

NSURLSession with upload stream - subclassing NSInputStream - com.apple.NSURLConnectionLoader exception

Basic task I have some multiplatform library which is using some C++ stream interface. I have to use this stream interface to upload data by NSURLSession. My implementation should work on OS X and iOS (currently I'm testing on OS X) What I did Task…
Marek R
  • 32,568
  • 6
  • 55
  • 140
1
vote
2 answers

What happens to NSURLSessionTasks if app is killed

Let's say I have a running NSURLSessionUploadTask. What happens to the pending request if the app is killed or crashes during that timeframe? Will the task still complete or is it also terminated?
user187676
1
vote
0 answers

iOS 9 web application prompting for certificates every time

I have moved to iOS 9 beta and one of the web apps I have is prompting the users to accept the SSL Cert every day. Hence it is kind of getting cached for a day and then again prompts the user next day. This works OK with iOS 8.x. Any idea as to why…
bhalochele
  • 227
  • 3
  • 11
1
vote
2 answers

Using NSURLSession to POST, what is the correct way to post the variables?

I am following this tutorial: http://www.raywenderlich.com/2965/how-to-write-an-ios-app-that-uses-a-web-service. Trying to set up a basic web service. Seems like the tutorial is old material and ASIHTTPRequest is no longer continued. I have been…
Kex
  • 8,023
  • 9
  • 56
  • 129
1
vote
1 answer

NSURLSessionDataTask fails on simple HTTPS URL with error -1002

I'm writing a simple Twitter app for OS X and I'm currently stuck on downloading the user's profile image. This is the code responsible for downloading the image: let imageRequest: NSURLRequest = NSURLRequest(URL: NSURL(string: avatarURL)!) let…
Peter W.
  • 2,323
  • 4
  • 22
  • 42