Questions tagged [nsurlsession]
NSURLSession is the API for HTTP connections introduced in iOS 7 and OS X 10.9.
                                	
	nsurlsession
    
                            
                        
                    
            2,489
            questions
        
        
            612
            votes
        
        
            27
            answers
        
        
            383k
            views
        
    The resource could not be loaded because the App Transport Security policy requires the use of a secure connection
                I am facing the Problem when I have updated my Xcode to 7.0 or iOS 9.0.
Somehow it started giving me the Titled error
"The resource could not be loaded because the App Transport Security
policy ...
            
        
       
    
            457
            votes
        
        
            21
            answers
        
        
            544k
            views
        
    How to make HTTP request in Swift?
                I read The Programming Language Swift by Apple in iBooks, but cannot figure out how to make an HTTP request (something like cURL) in Swift. Do I need to import Obj-C classes or do I just need to ...
            
        
       
    
            226
            votes
        
        
            7
            answers
        
        
            186k
            views
        
    Send POST request using NSURLSession
                I'm trying to perform a POST request to a remote REST API using NSURLSession. The idea is to make a request with two parameters: deviceId and textContent.
The problem is that those parameters are not ...
            
        
       
    
            137
            votes
        
        
            13
            answers
        
        
            140k
            views
        
    NSURLSession/NSURLConnection HTTP load failed on iOS 9
                Tried to run my existing app on iOS9 but getting failure while using AFURLSessionManager.
__block NSURLSessionDataTask *task = [self.sessionManager dataTaskWithRequest:request completionHandler:^(...
            
        
       
    
            122
            votes
        
        
            10
            answers
        
        
            147k
            views
        
    Generate your own Error code in swift 3
                What I am trying to achieve is perform a URLSession request in swift 3. I am performing this action in a separate function (so as not to write the code separately for GET and POST) and returning the ...
            
        
       
    
            113
            votes
        
        
            7
            answers
        
        
            145k
            views
        
    Undocumented NSURLErrorDomain error codes (-1001, -1003 and -1004) using StoreKit
                I'm writing StoreKit-related code, and I'm getting some rather troubling error codes when I try to add a purchase to the queue.
So far, I've experienced error codes -1003 and -1004 and I can't find ...
            
        
       
    
            91
            votes
        
        
            7
            answers
        
        
            96k
            views
        
    NSURLSession: How to increase time out for URL requests?
                I am using iOS 7's new NSURLSessionDataTask to retrieve data as follows:
NSURLSession *session = [NSURLSession sharedSession];
NSURLSessionDataTask *dataTask = [session dataTaskWithRequest:
request ...
            
        
       
    
            73
            votes
        
        
            1
            answer
        
        
            20k
            views
        
    NSURLSession concurrent requests with Alamofire
                I'm experiencing some strange behaviour with my test app. I've about 50 simultaneous GET requests that I send to the same server. The server is an embedded server on a small piece of hardware with ...
            
        
       
    
            56
            votes
        
        
            7
            answers
        
        
            36k
            views
        
    How do I use NSOperationQueue with NSURLSession?
                I'm trying to build a bulk image downloader, where images can be added to a queue on the fly to be downloaded, and I can find out the progress and when they're done downloading.
Through my reading it ...
            
        
       
    
            55
            votes
        
        
            3
            answers
        
        
            27k
            views
        
    NSURLSession with NSBlockOperation and queues
                I have an app that currently uses NSURLConnection for the vast majority of its networking. I would like to move to NSURLSession because Apple tells me that is the way to go.
My app just uses the ...
            
        
       
    
            51
            votes
        
        
            4
            answers
        
        
            11k
            views
        
    NSURLSession dataTaskForRequest:completion: unrecognized selector sent to instance
                When trying to create my own session object NSURLSession() and request an url I get an unrecognized selector exception but when I use the shared session NSURLSession.sharedSession() everything works ...
            
        
       
    
            50
            votes
        
        
            1
            answer
        
        
            34k
            views
        
    How to get server response data in NSURLSession without completion block
                I am using NSURLSession for background image uploading. And according to uploaded image my server gives me response and I do change in my app accordingly. But I can't get my server response when my ...
            
        
       
    
            49
            votes
        
        
            4
            answers
        
        
            97k
            views
        
    How to send POST and GET request?
                I want to send my JSON to a URL (POST and GET).
NSMutableDictionary *JSONDict = [[NSMutableDictionary alloc] init];
[JSONDict setValue:"myValue" forKey:"myKey"];
NSData *JSONData = [...
            
        
       
    
            39
            votes
        
        
            2
            answers
        
        
            38k
            views
        
    Unexpected Non-Void Return Value In Void Function (Swift 2.0)
                I have been skimming the StackOverflow questions trying to figure out where I'm going wrong with my code, but I just can't seem to!  I am trying to convert my Swift 1.2 project to Swift 2.0, and am ...
            
        
       
    
            37
            votes
        
        
            8
            answers
        
        
            64k
            views
        
    How to make NSURLSession POST request in Swift
                Hi I am very beginner for Swift and I am trying to make NSURLSession "Post" request sending some parameter like my below code 
According to my below code response not coming from server can some one ...
            
        
       
    
            36
            votes
        
        
            5
            answers
        
        
            39k
            views
        
    How to get cookie from a NSURLSession with Swift?
                I have a NSURLSession that calls dataTaskWithRequest in order to send a POST request in this way
func makeRequest(parameters: String, url:String){
    var postData:NSData = parameters....
            
        
       
    
            36
            votes
        
        
            5
            answers
        
        
            14k
            views
        
    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 ...
            
        
       
    
            35
            votes
        
        
            3
            answers
        
        
            10k
            views
        
    Using NSURLSession from a Swift command line program
                I'm trying to test a little proof-of-concept command line app prior to integrating it into a larger app. What I'm trying to do is download some data using NSURLSession using this example. However it ...
            
        
       
    
            35
            votes
        
        
            3
            answers
        
        
            15k
            views
        
    Resume NSUrlSession on iOS10
                iOS 10 is going to be released soon so it worth to test applications for compatibility with it. During such test we've discovered that our app can't resume background downloads on iOS10. Code that ...
            
        
       
    
            34
            votes
        
        
            2
            answers
        
        
            19k
            views
        
    Set number of concurrent downloads with NSURLSessionDownloadTask
                I'm using the new NSURLSession API and allowing the user to download files. I'd like to try and tell my NSURLSession how many simultaneous downloads to run, but I don't see a way to do it. I'd like to ...
            
        
       
    
            33
            votes
        
        
            2
            answers
        
        
            32k
            views
        
    NSURLSession + server with self signed cert
                I have an app that is production along with a development server that has a self signed certificate.  
I am attempting to test NSURLSession and background downloading but can't seem to get past - (...
            
        
       
    
            30
            votes
        
        
            2
            answers
        
        
            10k
            views
        
    NSURLSession causing EXC_BAD_ACCESS
                I've noticed that implementing NSURLSessionDataDelegate and starting a task will very occasionally throw an EXC_BAD_ACCESS. The actual calling method that gives the error seems to vary but always ...
            
        
       
    
            29
            votes
        
        
            4
            answers
        
        
            29k
            views
        
    Showing the file download progress with NSURLSessionDataTask
                I want to display file download progress (how many bytes are received) of particular file. It works fine with the NSURLSessionDownloadTask .My question is I want to achieve the same with the ...
            
        
       
    
            29
            votes
        
        
            2
            answers
        
        
            4k
            views
        
    iOS 9: Crash on -[_NSXPCDistantObject methodSignatureForSelector:]
                I'm getting a strange bug: 
  Fatal Exception: NSInvalidArgumentException
  *** -[_NSXPCDistantObject methodSignatureForSelector:]: No protocol has been set on connection  connection
  to service ...
            
        
       
    
            28
            votes
        
        
            2
            answers
        
        
            26k
            views
        
    How can I get the Data from NSURLSession.sharedSession().dataTaskWithRequest
                class PostFOrData {
    let url = NSURL( string: "http://210.61.209.194:8088/SmarttvWebServiceTopmsoApi/GetReadlist")
    var picUrl = NSURL(string : "http://210.61.209.194:8088/SmarttvMedia/img/...
            
        
       
    
            28
            votes
        
        
            5
            answers
        
        
            15k
            views
        
    what is the advantage of using Alamofire over NSURLSession/NSURLConnection for networking?
                Can anyone help me in understanding these question : What is the advantage of using Alamofire over NSURLSession/ NSURLConnection? 
What are the differences between NSURLSession and NSURLConnection?
            
        
       
    
            27
            votes
        
        
            3
            answers
        
        
            38k
            views
        
    What is the biggest difference between NSURLConnection and NSURLSession
                NSURLSession is new network SDK than NSURLConnection from Apple. 3rd old choice is CFNetwork.
Question here is to figure out the biggest difference between them to understand why Apple is evolving ...
            
        
       
    
            26
            votes
        
        
            1
            answer
        
        
            15k
            views
        
    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 ...
            
        
       
    
            26
            votes
        
        
            3
            answers
        
        
            39k
            views
        
    How to cache using NSURLSession and NSURLCache. Not working
                I have a test app setup and it successfully downloads content from the network even if the user switches apps while a download is in progress. Great, now I have background downloads in place. Now I ...
            
        
       
    
            26
            votes
        
        
            4
            answers
        
        
            61k
            views
        
    NSURLSession/NSURLConnection HTTP load failed (kCFStreamErrorDomainSSL, -9813) in iOS 9 with Xcode 7.1
                I am using iOS 9 as target & using Xcode 7.1, tried everything as my level best for all the solutions of ATS but didn't work. Below is the following error description coming at console. If any ...
            
        
       
    
            25
            votes
        
        
            4
            answers
        
        
            30k
            views
        
    iOS 9.3 : An SSL error has occurred and a secure connection to the server cannot be made
                I am getting following error with self signed certificate
  Error Domain=NSURLErrorDomain Code=-1200 "An SSL error has occurred
  and a secure connection to the server cannot be made.
while testing ...
            
        
       
    
            25
            votes
        
        
            4
            answers
        
        
            13k
            views
        
    NSURLSessionConfiguration timeoutIntervalForRequest vs NSURLSession timeoutInterval
                With the new NSURLSession, there is now a timeoutIntervalForRequest on the NSURLSessionConfiguration object used to create the session.
But there is still a timeoutInterval on the NSURLRequest object ...
            
        
       
    
            24
            votes
        
        
            4
            answers
        
        
            13k
            views
        
    NSURLSession Memory Leaks occur when using web services in IOS
                I am building an app that uses a web service and to get information from that web service I use NSURLSession and NSURLSessionDataTask.
I am now in the memory testing phase and I have found that ...
            
        
       
    
            24
            votes
        
        
            3
            answers
        
        
            42k
            views
        
    Domain=NSURLErrorDomain Code 1202
                Hi I receive the following error:
  Error Domain=NSURLErrorDomain Code=-1202 \"The certificate for this server is invalid. You might be connecting to a server that is pretending to be “server-prod....
            
        
       
    
            24
            votes
        
        
            5
            answers
        
        
            16k
            views
        
    Prevent NSURLSession from caching responses
                Why does it cache responses. It returns previously fetched responses. It even works if turning off the network connection. Resetting the iOS simulator did not seem to work either. Making a request, ...
            
        
       
    
            24
            votes
        
        
            4
            answers
        
        
            17k
            views
        
    Best practices for making a queue of NSURLSessionTasks
                What are the best practices for making a serial queue of NSURLSessionTasks ?
In my case, I need to:
Fetch a URL inside a JSON file (NSURLSessionDataTask)
Download the file at that URL (...
            
        
       
    
            24
            votes
        
        
            1
            answer
        
        
            4k
            views
        
    Transition from RestKit to pure AFNetworking 2.0
                I'd been using RestKit for the last two years, but recently I've started thinking about transition from these monolith framework as it seems to be really overkill.
Here's my pros for moving forward:
...
            
        
       
    
            23
            votes
        
        
            1
            answer
        
        
            12k
            views
        
    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 ...
            
        
       
    
            22
            votes
        
        
            1
            answer
        
        
            31k
            views
        
    NSURLSession delegate vs. completionHandler
                I've always used completion handlers. With NSURLConnection and now with NSURLSession. It's led to my code being really untidy, especially I have request within request within request.
I wanted to try ...
            
        
       
    
            21
            votes
        
        
            5
            answers
        
        
            29k
            views
        
    iOS 9 ATS SSL error with supporting server
                I installed Xcode 7 and tried running my app under iOS 9.
I'm getting the infamous error: Connection failed! Error - -1200 An SSL error has occurred and a secure connection to the server cannot be ...
            
        
       
    
            21
            votes
        
        
            1
            answer
        
        
            14k
            views
        
    iOS - Best practice to save Images locally - NSCache vs Save in Document Directory
                I'm developing an app that similar to Instagram feed (tableviews with cells that contain images and some labels).
For all the data I'm getting from the database, I'm using Data Task (because it doesn'...
            
        
       
    
            21
            votes
        
        
            1
            answer
        
        
            1k
            views
        
    What happens if disk space runs out while using NSURLSessionDownloadTask in background?
                In a iOS 8.1 app I am using NSURLSessionDownloadTask to download an archive in the background which can sometimes get quite large. 
Everything works fine, but what will happen if the phone runs out ...
            
        
       
    
            20
            votes
        
        
            6
            answers
        
        
            37k
            views
        
    How to find and cancel a task in NSURLSession?
                I'm using an NSURLSession object to load images in my application. That could be loading several images simultaneously. 
In some moments I need to cancel the loading of one specific image and ...
            
        
       
    
            20
            votes
        
        
            5
            answers
        
        
            17k
            views
        
    NSURLSessionTask never calls back after timeout when using background configuration
                I am using NSURLSessionDownloadTask with background sessions to achieve all my REST requests. This way I can use the same code without have to think about my application being in background or in ...
            
        
       
    
            20
            votes
        
        
            1
            answer
        
        
            4k
            views
        
    Why is NSURLSession slower than cURL when downloading many files?
                I've been using cURL to download about 1700+ files -- which total to about ~290MB -- in my iOS app. It takes about 5-7 minutes on my Internet connection to download all of them using cURL. But since ...
            
        
       
    
            20
            votes
        
        
            3
            answers
        
        
            14k
            views
        
    NSURLSession background download - resume over network failure
                After reading the Apple documentation about the background download with the new iOS7 api (NSURLSession), I'm a bit disappointed. I was sure that Apple was managing the pause/resume over the network ...
            
        
       
    
            19
            votes
        
        
            6
            answers
        
        
            15k
            views
        
    NSURLSession completion block not called
                var session = NSURLSession.sharedSession()
session.dataTaskWithRequest(urlRequest, 
                            completionHandler: {(data: NSData!, 
                                                 ...
            
        
       
    
            19
            votes
        
        
            1
            answer
        
        
            30k
            views
        
    NSURLConnection deprecated in iOS9
                I want to download a file with a NSURLRequest and save it but in the line with the
NSData * data = ... happens an error. 
NSURL *Urlstring = [NSURL URLWithString:@"http://yourdomain.com/yourfile.pdf"...
            
        
       
    
            19
            votes
        
        
            1
            answer
        
        
            18k
            views
        
    How to cancel on-going HTTP request in Swift?
                My code does GET request like this:
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), { () -> Void in
    // ...
    let task = NSURLSession.sharedSession()....
            
        
       
    
            19
            votes
        
        
            3
            answers
        
        
            16k
            views
        
    How do you know when the NSURLSession object has been invalidated by iOS?
                I am seeing an error in my tests where occasionally I get the following iOS error:
A background URLSession with identifier {GUID} already exists!
Even though I call invalidateAndCancel on the ...