Questions tagged [nsurlsessiontask]

55 questions
53
votes
7 answers

How to disable caching from NSURLSessionTask

In my iOS app, I am using NSURLSessionTask to download json data to my app. I discovered that when I call the url directly from the browser, I get an up to date json and when it's called from within the app, I get an older version of the json. Is…
Van Du Tran
  • 6,289
  • 10
  • 41
  • 52
29
votes
5 answers

What is difference between NSURLSessionDataTask vs NSURLSessionDownloadTask

In latest apple introduce new NSURLSession in replace of NSURLConnection, so in there are different task , so what is the difference between NSURLSessionDataTask, NSURLSessionDownloadTask ? and in which scenario use NSURLSessionTask and where…
25
votes
1 answer

How do I unit test HTTP request and response using NSURLSession in iOS 7.1?

I'd like to know how to "unit test" HTTP requests and responses using NSURLSession. Right now, my completion block code does not get called when running as a unit test. However, when the same code is executed from within the AppDelegate…
Jane Wayne
  • 6,828
  • 9
  • 57
  • 97
19
votes
1 answer

Does NSURLSession for HTTP data task (NSURLSessionDataTask) runs in background thread or we will have to provide the queue?

I started to use NSURLSession by avoiding NSURLConnection now a days as it's a new and elegant API provided by Apple. Previously, I used to put call NSURLRequest in GCD block to execute it in background. Here is how I used to do in…
8
votes
5 answers

Handling NSURLSessionDownloadTask failure

Originially I thought that if a NSURLSessionDownloadTask finishes successfully URLSession:downloadTask:didFinishDownloadingToURL: method will get called, if it fails for some reason - URLSession:task:didCompleteWithError:. It works as expected on…
8
votes
1 answer

I need to upload lot of files (up to 100) to server using AFNetworking in a single streaming request that can provide me upload progress

There are couple of challenges I am facing with streaming request using AFNetworking 2.0. I want to upload lot of files (~50MB) to server and the request HAVE TO BE STREAMING. (otherwise app will crash due to memory pressure) I have tried various…
6
votes
2 answers

NSURLSessionTaskPriority seems to be ignored?

In this example I kick off 100 NSURLSessionDataTask at default priority but then set the last one to high priority. However it seems to have no effect at all as the last task still ends up running last. NSURLSession *session = ... NSURLRequest…
trapper
  • 10,375
  • 6
  • 31
  • 74
6
votes
1 answer

NSURLSession - iOS kills application in background while communicating with server

I am working on a BLE application that will always run in background. It gets health related data from the BLE peripheral and will upload the data to the server in realtime. I am using NSURLSession along with NSURLSessionUploadTask created using…
kkumpavat
  • 452
  • 2
  • 10
4
votes
1 answer

NSURLSession didCompleteWithError:gets called with NSError is nil

Scenario is taking the app to background and foreground multiple times when its uploading is in progress,didCompleteWithError: method is called while taking app to foreground with error parameter is null. Probabilty is 1/3. How do i find out what…
Vani
  • 424
  • 4
  • 19
4
votes
1 answer

How to indicate network activity in status bar

I use Alamofire for networking in my iOS application. I need to run this app in iOS 7+. I want to indicate network activity in status bar, so I created this struct: struct ActivityManager { static var activitiesCount = 0 static func…
Deny
  • 1,398
  • 1
  • 11
  • 26
4
votes
1 answer

iOS8 extension background NSURLSession sandbox error

I'm trying to upload a file from a sharing extension in the Photos app, using a background NSURLSession. Because a background NSURLSession only supports an upload task using the uploadTaskWithRequest:WithFile: API, I first get the URL for the image…
3
votes
1 answer

Task created in a session that has been invalidated

I am getting the following crash on crashlytics which I can not reproduce on my device Fatal Exception: NSGenericException Task created in a session that has been invalidated at the following line NSURLSessionTask *task = [self.session…
Mahmoud Adam
  • 5,422
  • 5
  • 35
  • 61
3
votes
1 answer

AuthenticationMethodServerTrust is nil in iOS 9

I have been trying to implement a way to do public key pinning in my iOS 8+ app using NSURLSession. What I do is just implement the delegate method didReceiveChallenge and get the challenge.protectionSpace.authenticationMethod and check if it is…
3
votes
3 answers

How to determine when NSURLSessionTask's request begins?

I use NSURLSessionTasks and I'm trying to monitor how long some of my HTTP Requests take, what delegate method (or something else) can I monitor for when the NSURLSessionTask actually makes the initial request? If this were a NSURLConnection inside…
Shizam
  • 9,507
  • 8
  • 47
  • 81
3
votes
1 answer

NSURLSessionTask completionTask never get call in main queue using GCD

I am using iOS 7 NSURLSession to do some simple GET to a RESTful service. This is what i did: NSURLSessionConfiguration *sessionConfig = [NSURLSessionConfiguration ephemeralSessionConfiguration]; _session = [NSURLSession…
1
2 3 4