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

I'd like to actualize `curl --header $1` by Swift.( Header of NSURLSession)

I'd like to manipulate the following curl into swift.I have no idea how to write header of NSURLSession in Swift. curl -X GET --header "X-Auth-Token: abcdef"…
Toshi
  • 1,293
  • 3
  • 19
  • 37
1
vote
1 answer

Swift: Return JSON string from NSURLSession task

I'd like to get token as String type, however the following code returns error as " "String" is not convertible to "Void" ". Could you tell me what is the problem? In order to parse JSON, I used SwiftyJSON func authentication() -> String { let…
Toshi
  • 1,293
  • 3
  • 19
  • 37
1
vote
2 answers

Swift can't send URLRequest at all?

No matter what I do it seems I'm unsuccessful in sending requests. Given the below sample code I copied word for word just to see the results. Yet nothing happens, I'm really confused and need help figuring out why i can send requests fine with…
MrSSS16
  • 449
  • 3
  • 7
  • 21
1
vote
0 answers

how to get the number of resource files in UIWebview in swift

Now I can use the following method UIWebView display a webpage and get the page's html file length correctly. let urlAsString = "http://www.yahoo.com" let testurls = NSURL(string: urlAsString) let session_config =…
Victor LI
  • 31
  • 3
1
vote
1 answer

Not able to get the download progress in AFNetworking

I am trying to download a file using AFNetworking 2.0 using the following piece of code AFHTTPRequestSerializer *serialize = [AFHTTPRequestSerializer new]; [serialize setAuthorizationHeaderFieldWithUsername...// set the auth header with username and…
1
vote
3 answers

error back when using nsurlsession to access a webservice several times in a for loop

I need to get image information from server, such image name, image id. Then use image id as one of parameters to make post, get image actual data. More specific, there are three images I should get. First, I use getImageInfo to get image…
attolee
  • 602
  • 1
  • 9
  • 22
1
vote
1 answer

How do I access Node JS TLS Server from iOS NSURLSession

Ok, so this question has multiple technologies that can play into my question so here it goes. On my server side, I have a Node JS script running with a basic TLS server (Including a certificate and key from VeriSign) Like the following: var tls =…
Micaiah Wallace
  • 1,101
  • 10
  • 17
1
vote
0 answers

JSON to NSDictionary to Dictionary

I am trying to pass an API server response to Dictionary so I can later iterate values for keys. I understand it is a common problem, so I expect best and common practices here. Building on a Jameson Quave's POST Tutorial I am connecting to API via…
thinkswift
  • 528
  • 1
  • 5
  • 15
1
vote
0 answers

iOS app written Swift, Get API and show it on table view

On Xcode project written by Swift, I want to get API and show mysql data in table view. Based on information on the web, I've written following code, however it cannot work. At the following point, I got error "empty" command. Could you help me to…
Toshi
  • 1,293
  • 3
  • 19
  • 37
1
vote
1 answer

Upload image in a share extension results in NSURLErrorDomain Code=-997

I try to implement an extension with which the user can share an image on App.net. After a lot of trial and error I'm finally out of ideas. I have a framework to create the request. The request is a POST request with Content-Disposition: form-data.…
dasdom
  • 13,975
  • 2
  • 47
  • 58
1
vote
1 answer

NSURLErrorDomain code = -1002 despite escaping restricted chars

I have the following request code written (using the SwiftHTTP library) func performTagRequest(detail : String){ var request = HTTPTask() var formattedDetail = detail.stringByReplacingOccurrencesOfString("\"", withString: "", options:…
kidCoder
  • 354
  • 4
  • 17
1
vote
0 answers

Uploading images to s3 bucket and then uploading images' links to my server in background

I have a generic question, experienced developers may laugh at me when they read that but I couldn't manage it somehow. Basically, I want to upload images from filesystem to my amazon s3 bucket and after that upload links of these images to my…
1
vote
0 answers

Using NSURLSession (in Swift) to get data

I've been searching around to learn how to get some data using NSURLSession in Swift. There is a general pattern being repeated on the internet for making an http request using NSURLSession, and it looks a lot like this: let url = NSURL(string:…
H_H
  • 605
  • 1
  • 9
  • 13
1
vote
1 answer

NSURLErrorFailingURLPeerTrustErrorKey in Swift playground

The playground code at the bottom works as expected when the URL is http://www.apple.com and fails when the URL is https://www.apple.com NSURLErrorFailingURLPeerTrustErrorKey I'm guessing that there is something wrong with sharedSession and https?…
adamek
  • 2,324
  • 3
  • 24
  • 38
1
vote
1 answer

Failure to return to calling function from NSURLSession delegate without killing the task

I'm using Swift in Xcode 6.2 (beta) but had the same problem on the 6.1 release version. I'm trying to use NSURLSession and believe I have it set up correctly (see code below). The problem is that I have a delegate setup to deal with a redirect…
syntheticgio
  • 588
  • 6
  • 25