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

How to POST JSON data using NSURLSession in swift

I am stuck with the below code. How do I set the param and in post method? let params:[String:Any] = [ "email" : usr, "userPwd" : pwdCode] let url =…
dhaval shah
  • 4,499
  • 10
  • 29
  • 42
1
vote
1 answer

NSURLSession malloc_error

I am getting an intermittent malloc error with NSURLSession for uploads -(void)URLSession:(NSURLSession *)session task:(NSURLSessionTask *)task didCompleteWithError:(NSError *)error{ NSHTTPURLResponse *response = (NSHTTPURLResponse…
Ryan Heitner
  • 13,119
  • 6
  • 77
  • 119
1
vote
1 answer

How to run multiple NSURLSessionDownloadTask's so I can download multiple user photo streams from Instagram?

// // ViewController.swift // Fashun // // Created by Alex Macleod on 20/10/14. // Copyright (c) 2014 Alex Macleod. All rights reserved. // import UIKit class ViewController: UIViewController, UICollectionViewDelegateFlowLayout,…
alemac852
  • 99
  • 1
  • 11
1
vote
2 answers

iOS: Cannot make GUI changes inside NSURLSession delegate

I have a problem with some GUI components in my iOS app when using NSURLSession delegates. I have a UITableViewController which show different map areas to a user. The user can pick one of these areas and I will push a new UIViewController showing…
Espen
  • 110
  • 8
1
vote
1 answer

How to hook NSURLSession methods with theos?

I created a tweak project using rpetrich's theos and wanted to hook NSURLSession methods but the hooks don't seem to get invoked? Why? This is my Tweak.xm code: %hook NSURLSession - (NSURLSessionDataTask *)dataTaskWithRequest:(NSURLRequest…
radj
  • 4,360
  • 7
  • 26
  • 41
1
vote
0 answers

NSURLAuthenticationChallenge issue

I'm writing an app for a customer's web-service. The service is a cloud storage. So, one of my tasks is to upload all photo gallery to this cloud. While solving this problem, i faced the following issue. I'm using a NSURLSession for that, and some…
Nikita Semenov
  • 2,111
  • 4
  • 18
  • 31
1
vote
0 answers

AFNetworking 2.4 (AFURLSessionManager/AFHTTPSessionManager) vs NSURLSession in iOS 7/8

I'm hoping someone can help me understand all the differences at large between the latest version of AFNetworking (at the time of this writing, v2.4.1) and NSURLSession in the context of iOS 8. I'm not super savvy when it comes to doing this kind of…
Danchez
  • 1,266
  • 2
  • 13
  • 28
1
vote
1 answer

How to stop the webservice call when we move to another view

I am doing one application. In it, I did the web service part for each view. So when I moved to another view without completion of present view we service, then I need to stop the web service call in the present view. Please tell me how to do…
1
vote
1 answer

NSURLSession & NSURLSessionConfig - Discarding Config Headers

I am having an issue with NSURLSession & NSURLSessionConfiguration and I am not sure if it is my code or I have an incorrect understanding of how the framework behaves. The issue I am facing is that headers I set at the session level are not…
1
vote
1 answer

Call completion handler on background fetch with multiple NSURLSessions

I have multiple web services to be checked and downloaded in the background of my app, using NSURLSession to do this. When the app is in the background I use this code: -(void)application:(UIApplication *)application…
Jorn
  • 1,054
  • 9
  • 25
1
vote
2 answers

How to get the downloaded data of a failed NSURLSessionDownloadTask?

I would like to know if I can retrieve the parial downloadede data of a failed NSURLSessionDownloadTask. My use case is: I launch a download of a 1024MB file 512MB are downloaded The download fails because of network interruption When the…
yostane
  • 383
  • 1
  • 4
  • 19
1
vote
1 answer

Does using NSCache to cache image downloads waste memory as NSURLSession ready caches?

I know NSURLSession uses NSURLCache to cache HTTP responses, so if I use NSCache to cache image downloads due to its own advantages, am I having two copies in memory for each cache, and thus being wasteful? If so, how do I stop NSURLSession from…
Doug Smith
  • 29,668
  • 57
  • 204
  • 388
1
vote
2 answers

NSURLSession dataTaskWithRequest completionHandler fetching NSZeroData?

I am trying to download some XML from the Stack Exchange API. However, I'm not getting any results back. The URL brings up the XML when accessed in the browser, but I can't seem to get that in the form of an NSData object. Or rather, I keep ending…
PopKernel
  • 4,110
  • 5
  • 29
  • 51
1
vote
1 answer

Is it possible to build an asynchronous image downloading mechanism for UITableViews with just NSURLSession? How?

I want to build an image downloader for my UITableView so images can be loaded asynchronously into the table view. With NSURLSession automatically using NSURLCache to cache HTTP requests, will I be able to depend on that solely as my caching…
Doug Smith
  • 29,668
  • 57
  • 204
  • 388
1
vote
1 answer

How do I fire-off the NSURLSession w/completion before the UICollectionView delegate methods?

The following Objective-C Code processes the NSURLSession code (via viewDidLoad()) before the UICollectionView's delegate (which is what I want): --- Session --- --- Session --- --- {CellForItemAtIndexPath} --- --- {CellForItemAtIndexPath} --- ---…
Frederick C. Lee
  • 9,019
  • 17
  • 64
  • 105