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

Post Request using Nsurlsession Cache response

When i try to call post request using nsurlsession cannot able to cache the response.Please help me out. Thanks in advance
1
vote
2 answers

What is the best practice to call URL in apple watch?

What is the best practice to call API from Apple watch use sendMessage "watchConnectivity" from Apple watch to iPhone to call the API or use NSURLSession to call the API from the watch itself ?
Bassant Ashraf
  • 1,531
  • 2
  • 16
  • 23
1
vote
1 answer

iOS Share Extension NSURLSession not working on iOS 9

So I have this iOS Share Extension for my app that sends a result to my server in didSelectPost() when the 'POST' button is clicked. It all works fine on simulator; the request is sent and I can see data packets going out in Charles. On iOS 9, the…
Max One
  • 73
  • 1
  • 9
1
vote
1 answer

How to show progress view for task getting executed in background thread

I am using NSURLSession's dataTaskWithRequest to download data to my app. Currently I show an activity view overlay on my view controller when my app downloads data from web server. My user requested me to show a custom animation that tracks the…
PK20
  • 1,066
  • 8
  • 19
1
vote
2 answers

Make sync request with NSURLSession

I call some function in another thread: dispatch_async(dispatch_get_global_queue(priority, 0)) { self.someFunction() } Then in this function i want do synchronous request: let config =…
Arti
  • 7,356
  • 12
  • 57
  • 122
1
vote
2 answers

What is the format to send an NSDictionary on an HTTP Post?

I have this structure in a web service: { "user": { "email":"prueba@hotmail.com", "password":"12345678", "objectId":"2334jklwf", "token":"12334023ijrdadfsdoifj" } } I need to make an HTTP POST using…
abnerabbey
  • 125
  • 1
  • 10
1
vote
1 answer

Warning about sendsynchronousRequest:returningResponse:error: is deprecated:first seprecated in ios 9-

And it says use [NSURLSession sharedsession] dataTaskwithRequest:request completionHandler:] So here my code: NSData *returnData = [NSURLConnection sendSynchronousRequest:request returningResponse:nil error:nil]; I changed above code to like…
jj1
  • 135
  • 2
  • 11
1
vote
2 answers

Showing image from imageURL in UICollectionView using server response

What I am trying to do is render image in a UICollectionView from imageUrl which is coming from server as response. There is no issue with UICollectionView as I have already tested it with hardcoded URL. The problem starts when I try to load it with…
Kunal Kumar
  • 1,722
  • 1
  • 17
  • 32
1
vote
1 answer

Sending simple POST in Swift, getting "Empty Post" response

I have registration page in my iOS app that I'm trying to write in Swift. The first thing I'm testing out is sending a POST with the email address, this is the way I'm doing so: var bodyData = ("userEmail=%@\" \" &userPassword=%@\"…
Henry F
  • 4,960
  • 11
  • 55
  • 98
1
vote
1 answer

login and completion handler

I'm developing an app with a login page. When the app is launched, the login screen is shown, and you cannot access the app until you are connected. To connect to the app, you enter your username and your password. When you press the "connect"…
nommis
  • 116
  • 10
1
vote
0 answers

NSURLSession at https (kCFErrorDomainCFNetwork Code=310)

I got a Error Message When I use NSURLSession to connect a web Service with a https connection (Xcode 7.1) the error message is following~ Error Domain=kCFErrorDomainCFNetwork Code=310 "The operation couldn’t be completed.…
Yung-Yi
  • 21
  • 4
1
vote
0 answers

Using NSURLSession to upload a file to Django form from iOS (Swift)

I'm trying to upload a text file (.csv) saved within my iOS application's tmp directory to a web server at a url that uses a Django form (and works fine from a browser uploading files off a computer). I'm having trouble getting the Swift code to…
sech16
  • 11
  • 3
1
vote
2 answers

downloadTaskWithRequest confusing behaviour (swift , IOS )

I do not understand the following and hope some does :-) I am downloading a file from an url (10 minutes downloadtime), which works fine, when the download completes. BUT: When I simulate a crash or internet-interruption after a minute and restart…
mcfly soft
  • 11,289
  • 26
  • 98
  • 202
1
vote
1 answer

NSURLSession get response from Servlet

Currently, I am using NSURLSession and HTTPPost method to upload data to Java servlet. The java servlet will parse the data received and update it into database. let dataTest:NSData = dao.readStringFromDb().data let request =…
PK20
  • 1,066
  • 8
  • 19
1
vote
1 answer

Returning a block inside another block sometimes delayed

I’m trying to migrate to NSURLSession from NSURLConnection. I’ve used delegate methods to return the JSON object IN NSURLConnection previously. But now I’m looking to implement blocks to return the JSON object. I have my own block to return the JSON…
Matt
  • 1,711
  • 18
  • 20