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

How to run a NSURLSession in ios in background mode

I was trying to open a URL session for a chunked response, I am able to achieve this by setting backgroundSessionConfigurationWithIdentifier in NSURLSessionConfiguration object. The URL session still runs if app goes to background, but the session…
Birajendu
  • 29
  • 5
1
vote
1 answer

Assigning data from closure after dataTaskWithURL resulting in nil values

I apologize for the simplicity of my description, I'm new to Swift as a language. I have a REST api which provides all the data to my app. I am attempting to populate a table view from a JSON feed. Essentially, I am trying to my best to stick to…
Sean
  • 1,304
  • 11
  • 26
1
vote
2 answers

Moving from NSURLConnection to NSURLSession for SOAP POST in Swift

I am trying to move over from NSURLConnection over to NSURLSession for a SOAP post, but seem to have issues with the NSURLSessionDataDelegate. Here is the old code in NSURLConnection that works fine: let soapMessage = "
Dave
  • 351
  • 4
  • 18
1
vote
1 answer

Set NSData dataWithContentsOfURL timeout

So i have this method in my app that returns BOOL if and update is available for my apps content - (BOOL)isUpdateAvailable{ NSData *dataResponse=[NSData dataWithContentsOfURL:[NSURL URLWithString:@"url that returns json object"] ]; …
ram obrero
  • 197
  • 10
1
vote
1 answer

How is running the background network task on iOS

NSURLSession provides the ability to run something under background with URLSessionDidFinishEventsForBackgroundURLSession and here is the simple intro For networking layer, most iOS dev get used to build on AFNetworking or Alamofire, which is the…
Forrest
  • 122,703
  • 20
  • 73
  • 107
1
vote
0 answers

NSURLSessionUploadTask & API Calls

Problem: I am building a photo organization/backup iOS app which requires users photos from their device galleries to be uploaded to our server. User creates his profile and logs into the app and his gallery is scanned for images.The uploads happen…
SayeedHussain
  • 1,696
  • 16
  • 23
1
vote
1 answer

Connection retry in NSURLSession

I want to implement the connection retry in NSURLSession. Is there any parameter we need to set to achieve this like 'timeoutIntervalForRequest' and NSURLSession takes the responsibility to retry the connection. If there is no any parameter for…
1
vote
1 answer

iOS - Parse list of filenames/directories for a Web URL?

I want to get all filenames and directories from a provided web url so I can easily create links to those files/directories in my app. I am having trouble figuring out the best way to parse the text file returned when using NSURLSession's…
JimmyJammed
  • 9,598
  • 19
  • 79
  • 146
1
vote
0 answers

AFHTTPSessionManager posting video swift

I am trying to upload a video in background using AFNetworking > AFHTTPSessionManager Post method. I want it to conitune uploading even if the app is suspended. But I get error while executing this code, it logs no error, and points to nowhere in…
1
vote
0 answers

How to use NSURLSession to upload image to server

With iOS 9, I was forced to change my old NSURLConnection with NSURLSession. I had a working code to upload an image from my phone to my server, with a piece of php code to store the image. There are plenty of nice tutorials out there, like this…
Tom Tallak Solbu
  • 559
  • 6
  • 20
1
vote
1 answer

Not able to use custom delegate in NSURLSession

I have a NSURLconnection implementation and am trying to migrate to NSURlsession for IOS-9. NSURLconnection implementation: @property (nonatomic, strong, readwrite) NSURLConnection * connection; Custom delegate methods: …
CodeTry
  • 312
  • 1
  • 19
1
vote
1 answer

Converting NSData(contentsOfUrl) to NSURLSession?

I've been working on an app for watchOS 2, and am led to believe that my function, which uses NSData(contentsOfUrl) to download some JSON data, may be too heavy, causing the app to crash. My research has led me to believe that NSURLSession is the…
ZbadhabitZ
  • 2,753
  • 1
  • 25
  • 45
1
vote
1 answer

iOS9 NSURLSession HTTP/2

In wwdc viedo [[networking with nsurlsession]], they say NSURLSession supports HTTP/2 protocol automatically; but when i use this code, let sessionConfig = NSURLSessionConfiguration.defaultSessionConfiguration() let session =…
1
vote
1 answer

NSURLSession's dataTaskWithRequest: returns nil

I've got a really strange error. I have the following line in code: NSURLSessionDataTask *task = [self.session dataTaskWithRequest:request]; after execution of which the task is nil! This case is not documented anywhere and I couldn't find any…
frangulyan
  • 3,580
  • 4
  • 36
  • 64
1
vote
0 answers

Continue NSURLSession Data Task when app enters background

I have an application that retrieves JSON data from my server and enters it in to my Core Data model. I have this working reasonably well, minus a few issues with random EXC_BAD_ACCESS errors that I haven't figured out yet. During this dataTask,…
Sawyer05
  • 1,604
  • 2
  • 22
  • 37