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 save the image in my server

i am uploading the Image,which is taken from the camera or gallery. i am successfully getting the image and when i uploading it i am getting error in simulator User_file=(null). My Updating code is -…
NAVEEN KUMAR
  • 669
  • 6
  • 25
1
vote
2 answers

How to access NSURLSession temp file in UIWebview local HTML file?

I have downloaded a json file (data.json) using NSURLSession. I am trying to access this file from a local html file (main project folder) myfile.html which is displayed via UIWebView. From NSLog I have identified the temp file location is…
MrDave
  • 417
  • 1
  • 6
  • 18
1
vote
1 answer

Request desktop html NSURLSession

I am trying to parse some metadata from the head tags of various websites on iOS. Unfortunately, some of those sites (namely Vimeo) do not send the same metadata when rendering the mobile page as they do the desktop one. I need to request the html…
AttilaTheFun
  • 701
  • 2
  • 11
  • 19
1
vote
1 answer

NSURLSessionDelegate methods not called in TestFlight installs

I am building an app targeting iOS 8.0 that needs to download files that are up to 250Mb. I had a version of the download code roughly working using Alamofire but I recently replaced that with a pure NSURLSession implementation. This new…
Hélène Martin
  • 1,409
  • 2
  • 15
  • 42
1
vote
0 answers

Soap with Swift2 CFNetwork SSLHandshake failed (-9824)

I'm trying to change my Soap service to Swift2, but I get an error: CFNetwork SSLHandshake failed (-9824) I tryed to google it, but I still get same error, full error here: 2015-12-28 09:28:01.674 SoapSwift[501:7558] CFNetwork SSLHandshake …
Ben
  • 761
  • 1
  • 12
  • 35
1
vote
0 answers

NSURLsession not working in loop

Im trying to make request to multiple URLs to download the HTML and later turn it into a JSON format. Where I'm running into trouble is when i try to make request to multiple URLs in the for loop. I'm no master on this with async requests so, this…
niwim
  • 21
  • 7
1
vote
0 answers

Getting an Authentication Failed error from server after hitting web service in Swift

The following below code is of hitting web service in swift by using NSURLSession .. I always get authentication failed message from server.Not able to get what is missing in request body. let urlString:String = "\(BaseURL)"+"user_register.php?" …
Som
  • 128
  • 9
1
vote
0 answers

NSURLSession delegate implementation returns only of html

Let's go straight into code. First in appDelegate, I register my connection protocol: [NSURLProtocol registerClass:[MyURLConnection class]]; Here's what my connection class looks like: +(BOOL)canInitWithRequest:(NSURLRequest *)request { return…
Parag
  • 963
  • 2
  • 10
  • 27
1
vote
5 answers

Post request with raw body using NSURLSession

I have stuck here. Below is my code for Post request with raw body using NSURLSession. I got response = NULL and no error. NSString* stringRequest = @"https://chocudan.com/api/shops/by_ids"; NSURL* urlRequest = [NSURL…
sunsunai
  • 161
  • 4
  • 11
1
vote
0 answers

NSURLSessionTask, $_POST key => value pairs disappear over cellular?

In my iOS app, I have an NSURLSessionTask that works as it should over WiFi connections to the internet (and thus it must be formatted correctly). But when I connect over a cellular network my php on the server reports that no $_POST key => value…
narco
  • 830
  • 8
  • 21
1
vote
0 answers

iOS google reverse geocode not working properly

For reverse geocoding am using the following method, [api getRequest:[NSString stringWithFormat:@"https://maps.googleapis.com/maps/api/geocode/json?latlng=%f,%f&key=%@&language=%@",latV,lonV,kGoogleAPIKey,@"en"] withCompletionHandle:^(NSData *data)…
1
vote
0 answers

Retry with callback in Swift

I wrote the following function: func getStringFromRequest(jsonString:NSDictionary, callback: (NSDictionary, String!) -> Void) { let request = NSMutableURLRequest(URL: NSURL(string: "https://***.*.*.**:****" )!) var result =…
Amit Raj
  • 1,358
  • 3
  • 22
  • 47
1
vote
1 answer

Setting params in HTTP POST request for swift

I am making a post request with following params in HTTPBody: filter:{“name”:"john”,”city”:”NY"} I googled it but couldn't find the syntax let params : [Dictionary>] = [ [ "filter" : [ …
Danboz
  • 561
  • 1
  • 5
  • 14
1
vote
0 answers

Swift NSURLSession Download Task not retrieving image assets

I am downloading an html page which looks like this from a local Jetty 9 server.

Hello

When I navigate to that page in Chrome, my server receives requests…
EthanP
  • 1,663
  • 3
  • 22
  • 27
1
vote
1 answer

running 2 tasks on one NSURLSession.sharedSession

I am trying to do 2 HTTP requests in the first request i will get a var that will be used in the second request. My problem is when I do it using the code below it just runs the second request without running the first. let url =…
Seif Hatem
  • 1,433
  • 2
  • 12
  • 20