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
0 answers

Missing boundary while uploading video using NSURLSessionUploadTask

I have an error on the server while uploading a video using NSURLSessionUploadTask, the server error states: PHP Warning: Missing boundary in multipart/form-data POST data in Unknown on line 0 and here is my code: NSURLSessionConfiguration…
Laur Stefan
  • 1,519
  • 5
  • 23
  • 50
1
vote
1 answer

Swift NSURLSession NSURLRequest Cookies are not accepted

I'm new to swift and OS X programming. For my first steps I wanted to create a command line tool which logs me into the webinterface of my mobile carrier, and then shows the amount of my data left. I began to write a wrapper around NSURLSession to…
devnull
  • 558
  • 4
  • 18
1
vote
0 answers

iOS - Why is this method so slow?

I have an iOS method that is now deprecated --NSURLConnection sendSynchronousRequest. This method worked and was fast. I must be doing something wrong with the new method, as it is unacceptably slow. The new method code I'm showing the whole…
ICL1901
  • 7,632
  • 14
  • 90
  • 138
1
vote
1 answer

NSUrlSession: is it possible to upload files in the background?

Using NSUrlSession with a background configuration let's me download files even if the app gets terminated by iOS. Being curious, I tried to add an upload task and noticed that it won't continue, even not if the app is only suspended. Apple talks…
Krumelur
  • 32,180
  • 27
  • 124
  • 263
1
vote
1 answer

NSURLSession crash

Just on one client device iPhone4s with iOS7.1 we have crash with stack: Thread : Crashed: com.apple.NSURLSession-work 0 CoreFoundation 0x2d6419be CFURLCopyScheme + 49 1 CFNetwork 0x2d30b67d _urlIsHTTPish + 8 2…
Igor Palaguta
  • 3,579
  • 2
  • 20
  • 32
1
vote
3 answers

NSURLSessionDownloadTask Delegates not calling didWriteData method

I'm starting to implement a download method using NSURLSession and successfully downloaded different files from multiple request. But now I wanted to add a progress track, however the delegates for download progress is not being triggered. Here is…
1
vote
1 answer

Swift NSURLSession access delegate within closure

I am new to swift so bear with me. I am using NSURLSession and I need to access a delegate I have defined when the response is complete. This is my class property var delegate: APIClientDelegate? Here is the relevant section var configuration…
lampwins
  • 920
  • 1
  • 9
  • 25
1
vote
0 answers

iOS NSURLSessionUploadTask is stuck

I'm trying to send HTTP post message in the implementation NSFileProviderExtension's method itemChangedAtURL:(NSURL *) using uploadTaskWithStreamedRequest, after I resume the task the delegate method needNewBodyStream is called and after it nothing…
rsapps
  • 11
  • 1
1
vote
1 answer

NSURLSession uploadTaskWithRequest with mime type?

I'm trying to upload an image to a cloud storage with NSURLSession. let data = UIImageJPEGRepresentation(imageAttachment, 1) NSURLSession.sharedSession().uploadTaskWithRequest(request, fromData: data) The image has been successfully uploaded, but…
Andree
  • 3,033
  • 6
  • 36
  • 56
1
vote
4 answers

How to use NSURLSession's dataTaskWithURL with Swift 2?

While using Swift 1 this code worked fine: let connectionSession = NSURLSession.sharedSession() let task = connectionSession.dataTaskWithURL(currentURL!, completionHandler: { (data, response , error) in ... In Swift 2…
Georg Tuparev
  • 441
  • 2
  • 6
  • 11
1
vote
1 answer

NSURLSession background transfer timeout not fired

When I try to start a basic NSURLSession transfer while the network is offline (air plane mode), with NSURLSessionConfiguration defaultSessionConfiguration and ephemeralSessionConfiguration, I of course immediately receive the NSError…
1
vote
2 answers

Cancel NSURLSession if user taps twice in swift iOS

Im using NSURLSession which is preferred according to this thread. How to make an HTTP request in Swift? let url = NSURL(string: "http://www.stackoverflow.com") let task = NSURLSession.sharedSession().dataTaskWithURL(url!) {(data, response, error)…
Zeezer
  • 1,503
  • 2
  • 18
  • 33
1
vote
1 answer

Multiple NSURLSessions Causing UITableView Problems

I'm running into a bit of a strange problem here. One of my NSURLSessions is in charge of getting information for restaurant information that I have stored (restaurant name, restaurant's logo URL, etc), and then the second NSURLSession is in charge…
pwoerfulafhjksdh
  • 381
  • 1
  • 3
  • 11
1
vote
1 answer

NSURLSession ignoring NSURLSessionConfiguration Cache Policy

Even after setting the Cache Policy, my NSURLSession is still loading cached data: let url = NSURL(string: urlString); var sessionConfig = NSURLSessionConfiguration.defaultSessionConfiguration(); sessionConfig.requestCachePolicy =…
Jake Chasan
  • 6,290
  • 9
  • 44
  • 90
1
vote
1 answer

UI Slow to Update *ONLY* If Called In Response To Change Occurring in NSURLSessionUploadTask Completion Block

The app interacts with php scripts on my server. A user can create a booking, and details are written to a database. Subsequently, they can cancel that booking. Within the app, a booking is an object, responsible for gathering its own details from…