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
10
votes
2 answers

Pause,Resume,Cancel Upload Task Using NSURLSession UploadTask

I am developing an app to upload multiple files using NSURLSession, right now my files are successfully uploaded. But now what i want to achieve is to pause,resume and cancel the uploads just like we do in download tasks. Is it possible.? Any help…
Tabish Sohail
  • 1,040
  • 2
  • 9
  • 22
10
votes
1 answer

Function does not wait until the data is downloaded

I have the following function which downloads an image from server; func getImageFromServerById(imageId: String) -> UIImage? { let url:String = "https://dummyUrl.com/\(imageId).jpg" var resultInNSDataformat: NSData! let task =…
Berkan Ercan
  • 1,207
  • 3
  • 14
  • 31
10
votes
0 answers

NSURLSession background download over cellular possible in iOS 8?

I need to make small downloads initiated when my app is in the background and woken up by Significant Location Changes. BUT Apples documentation of NSURLSessionConfiguration…
10
votes
2 answers

AFNetworking Background Session Configuration for iOS 8 Extension

I'm currently developing an iOS 8 App Extension, and am having difficulty with this one last piece. In the rest of my app, I use an AFHTTPSessionManager subclass that I instantiate like this: + (MYAPIClient *)sharedClient { static MYAPIClient…
lramirez135
  • 2,872
  • 3
  • 18
  • 18
10
votes
1 answer

Swift NSURLSession and authentication

I am currently trying to change my code from using NSURLConnection to NSURLSession. One thing that is confusing me is authentication. My service that I am trying to connect is basic authenticated. In my former code I had the following method by…
Oliver Koehler
  • 711
  • 2
  • 8
  • 24
10
votes
1 answer

Uploading Image NSData via POST and NSURLSession

I'm trying to upload a single UIImage to a server, and everything seems to be okay except that the image is never uploaded. This is the code I'm using to upload the image in iOS: const NSString *boundaryConstant =…
jaggedcow
  • 1,405
  • 1
  • 12
  • 23
10
votes
2 answers

NSURLSessionDataTask dataTaskWithURL completion handler not getting called

I have been learning Objective C lately, and I decided to try connections. Everything was great with NSURLConnection, until I discovered it was outdated, and tried to work with NSURLSession. I am trying a very simple example, but can't seem to get…
ylc
  • 199
  • 1
  • 3
  • 9
10
votes
3 answers

NSURLSessionDownloadTask - downloads but ends with error

I am trying to download a pdf file. earlier when i used the completion handler block i was able to see the file in the tmp location. I then wanted to show download progress so i implemented the delegate methods. But i can now see the progress bar…
Tamil
  • 1,173
  • 1
  • 13
  • 35
10
votes
3 answers

How can I check that an NSData blob is valid as resumeData for an NSURLSessionDownloadTask?

I have an app that's using background downloads with the new NSURLSession APIs. When a download cancels or fails in such a way that NSURLSessionDownloadTaskResumeData is provided, I store the data blob so that it can be resumed later. A very small…
Ian Terrell
  • 10,667
  • 11
  • 45
  • 66
10
votes
2 answers

handleEventsForBackgroundURLSession never called when a downloadTask finished

I am using AFURLSessionManager, and set the manager as a singleton instance. - (AFURLSessionManager *)backgroundSession { static AFURLSessionManager *backgroundSession = nil; static dispatch_once_t onceToken; dispatch_once(&onceToken,…
snorlax
  • 163
  • 1
  • 9
10
votes
1 answer

HTTP PUT method with NSURLSession

I'm struggling with NSURLSession class introduced in iOS 7 SDK and I'm stuck at a point, where I need to call my REST API with PUT method. I've already implemented GET and POST methods, which are working fine using this: NSMutableURLRequest *request…
Sebastian Łuczak
  • 1,116
  • 8
  • 19
10
votes
2 answers

NSURLSession Delegate Queue

This seems weird. I can't seem to seem to successfully set an NSURLSession's delegateQueue on creation. - (void)viewDidLoad { [super viewDidLoad]; NSOperationQueue *queue = [[NSOperationQueue alloc] init]; …
Drewsmits
  • 1,384
  • 2
  • 14
  • 24
9
votes
3 answers

How to stop caching my HTTP request & response in ionic 3

I want to stop caching my API request and response which the native-http plugin stored its cache and its creating issue with my app. All-time API works fine but when I get a 404 or 401 error from the server it will cache it in my app and then after…
9
votes
3 answers

How to cancel a URL session request

I am upload multiple image to server using convert image to base64 and send image in a API as a parameter. But when we call api again and again then how to stop api calling on button click. I am using below code to call API. Thanks in advance let…
Gaurav Gupta
  • 593
  • 2
  • 10
  • 31
9
votes
2 answers

NSURLSession sharedSession default timeout

Would anyone know what are the timeouts configuration for [NSURLSession sharedSession]? I am doing some debugging and this information would be very helpful. Edit Apparently my question is not clear (!). I am not asking how to change the timeout. I…
vib
  • 2,254
  • 2
  • 18
  • 36