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

NSURLSession restart the request

I am using the NSURLsession for network calls. I need to store the details to perform the restart on network error or manually when user performs the sync from app. Do I need to store the NSURLsession object or NSURLSessionDataTask or taskIdentifier…
Raghav
  • 625
  • 1
  • 12
  • 31
1
vote
1 answer

WatchKit Retrieve Multiple URL Images

I am creating a conversation thread using WatchKit 2.0 and am having difficulty downloading multiple images within a conversation. I am able to get a single image using the WatchConnectivity sendMessage. I can get back NSData which I can use for the…
Mike Walker
  • 2,944
  • 8
  • 30
  • 62
1
vote
2 answers

Send Progress from NSURLSession to ViewController [swift - iOS]

I'm developing an app which handles some downloads in the background. I move the file to the documents directory and save it under the original name (using downloadTask.originalRequest?.URL!.pathExtension). So far so good. Using …
Holger
  • 356
  • 4
  • 11
1
vote
2 answers

How send post data with text parameter and image file?

I make an application that allows user to upload image and several to our server. If I just post text data my code successfully post data to the server but when I try to post text data with image data, my server throw an exception. here is my…
Ega Setya Putra
  • 1,645
  • 6
  • 23
  • 51
1
vote
1 answer

sendSynchronousRequest deprecated. How can I achieve the same thing with dataTaskWithRequest?

This might be a stupid question, but I have some issues changing my code to avoid some deprecated code in iOS9. I have created an app that logs in to a webpage. The webpage uses a username and a password which forwards to a page where a token has to…
fisher
  • 1,286
  • 16
  • 29
1
vote
0 answers

Is scheduling 50+ download tasks at once a wrong approach?

Is scheduling 50+ download tasks a wrong approach? By “scheduling” I mean creating NSURLSessionDownloadTask from a NSURLSession with “background” configuration and calling [task resume]. So I’m launching all tasks right away, but files are…
dariaa
  • 6,285
  • 4
  • 42
  • 58
1
vote
0 answers

Problems with Async NSURLSession calls in Playground

I'm trying to implement a custom Google search in IOS. For testing, I'm trying to test the request in a Playground. My search URL works fine in the browser (chrome), however in the playground the completion block isn't firing and I'm getting this…
GarySabo
  • 5,806
  • 5
  • 49
  • 124
1
vote
1 answer

iOS - Refreshing Expired Auth Token In NSURLSession

In my app, I need to add my authentication token in the HTTPHeadField for every NSURLRequest API call that I make to my server. This token is only valid for 2 days. When it becomes invalid, I'll receive a "token_invalid" error response from my…
Rafi
  • 1,902
  • 3
  • 24
  • 46
1
vote
1 answer

Replacing sendSynchronousRequest with NSURLSession in command line tools

Trying to replace deprecated sendSynchronousRequest calls in several command line tools I have written. The completionHandler is not getting called. Based on somewhat similar questions, I have tried using a semaphore, but still no joy. (Most…
rick
  • 51
  • 6
1
vote
2 answers

ios URLSession background download FIFO mechanism

I have an application which would support downloading the content to local disk. Users can choose the items they want to save. After downloading complete, I will unzip the downloaded file and encrypt then save to local. I use NSURLSession with…
kuokuo321
  • 1,603
  • 1
  • 10
  • 11
1
vote
2 answers

Return value in NSURLSession Error

I get below error while trying to return responseString Incompatible block pointer types sending 'NSString *(^)(NSData *__strong, NSURLResponse *__strong, NSError *__strong)' to parameter of type 'void (^)(NSData *__strong, NSURLResponse *__strong,…
9to5ios
  • 5,319
  • 2
  • 37
  • 65
1
vote
1 answer

Does NSURLSession automatically URL-encode the text of the URL?

Does NSURLSession automatically URL-encode the text of the URL? Or do you have to manually do it?
CommaToast
  • 11,370
  • 7
  • 54
  • 69
1
vote
2 answers

How can I achieve a "configurable" NSURLSession shared session?

I want to change the timeout on my HTTP requests. I'm on a project that uses extensively [NSURLSession sharedSession]. I know that I can't change the configuration of that session (it hasn't one at all). I know I can define a session with my own…
webo80
  • 3,365
  • 5
  • 35
  • 52
1
vote
2 answers

How to integrate NSUrlsession in ios

Hi I am very new to ios and in my app I am using NSUrlSession for integrating services. Here my main problem is when I get a response from the server, I can't handle them properly. When I get a correct response, then see the below json…
AbhiRam
  • 2,033
  • 7
  • 41
  • 94
1
vote
2 answers

NSURLSession gets the data properly, but returns nothing after Task.resume()

I am trying to connect my HTTP server to get data in JSON format. It connects and gets the data properly. I am able to print the data before task.resume() but, it doesn't print after task.resume() Also, the function returns empty object. I tried…
pininfarina
  • 123
  • 1
  • 12