nsurlsession

What is the biggest difference between NSURLConnection and NSURLSession

隐身守侯 提交于 2019-11-27 11:56:45
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 like these. Thanks The entire model is different. NSURLSession is designed around the assumption that you'll have a lot of requests that need similar configuration (standard sets of headers, etc.), and makes life much easier if you do. NSURLSession also provides support for background downloads, which make it possible to continue downloading resources while your app isn't running (or when it is in

How to get cookie from a NSURLSession with Swift?

只谈情不闲聊 提交于 2019-11-27 11:06:00
问题 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.dataUsingEncoding(NSASCIIStringEncoding)! var postLength:NSString = String(postData.length ) var request = NSMutableURLRequest(URL: NSURL(string: url)!) var session = NSURLSession.sharedSession() request.HTTPMethod = "POST" var error:NSError? //request.HTTPBody = NSJSONSerialization.dataWithJSONObject(postData,

How do I unit test HTTP request and response using NSURLSession in iOS 7.1?

坚强是说给别人听的谎言 提交于 2019-11-27 10:53:43
问题 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 executed from within the AppDelegate (didFinishWithLaunchingOptions), the code inside the completion block is called. As suggested in this thread, NSURLSessionDataTask dataTaskWithURL completion handler not getting called, the use of semaphores and/or dispatch_group is needed "to make sure the

Best practices for making a queue of NSURLSessionTasks

不羁岁月 提交于 2019-11-27 10:36:43
问题 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 ( NSURLSessionDownloadTask ) Here’s what I have so far: session = [NSURLSession sharedSession]; //Download the JSON: NSURLRequest *dataRequest = [NSURLRequest requestWithURL:url]; NSURLSessionDataTask *task = [session dataTaskWithRequest:dataRequest completionHandler:^(NSData *data, NSURLResponse *response,

How do I use NSOperationQueue with NSURLSession?

余生长醉 提交于 2019-11-27 10:17:54
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 seems like NSOperationQueue for the queue functionality and NSURLSession for the network functionality seems like my best bet, but I'm confused as to how to use the two in tandem. I know I add instances of NSOperation to the NSOperationQueue and they get queued. And it seems I create a download task with NSURLSessionDownloadTask , and multiple if I need multiple tasks, but I'm not sure how I put

How to programmatically add a proxy to an NSURLSession

怎甘沉沦 提交于 2019-11-27 07:20:19
Looking over the documentation of NSURLSession and NSURLSessionConfiguration , I was under the impression I should configure it with a dictionary like the following: // Create a dictionary to describe the proxy NSDictionary *proxyDict = @{ (NSString *)kCFProxyHostNameKey : @"myProxyHost.com", (NSString *)kCFProxyPortNumberKey : @"12345", (NSString *)kCFProxyTypeKey : (NSString*)kCFProxyTypeHTTP }; // Create a configuration that uses the dictionary NSURLSessionConfiguration *configuration = [NSURLSessionConfiguration defaultSessionConfiguration]; [configuration setConnectionProxyDictionary

How to get server response data in NSURLSession without completion block

别来无恙 提交于 2019-11-27 06:25:00
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 app uploading image in background because there is no completion block. Is there way to get response without using completion block in NSURLUploadTask ? Here is my code : self.uploadTask = [self.session uploadTaskWithRequest:request fromData:body completionHandler:^(NSData *data, NSURLResponse *response, NSError *error) { NSString *returnString = [[NSString alloc] initWithData:data encoding

NSURLSession: uploading assets with background transfer

纵饮孤独 提交于 2019-11-27 06:21:15
问题 What's the best approach to use background transfer to upload assets from gallery? Seems like uploadTaskWithRequest:fromData: doesn't work with NSURLSession created with backgroundSessionConfiguration since it causes an exception: "Terminating app due to uncaught exception 'NSGenericException', reason: 'Upload tasks in background sessions must be from a file". Judging from the exception description background transfer shouldn't work with streamed upload tasks too. Fair enough.

Resume NSUrlSession on iOS10

我与影子孤独终老i 提交于 2019-11-27 06:03:13
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 worked well on previous versions does not work on new one, both on an emulator and on a device. Instead of reducing our code to minimal working test case I've searched internet for NSUrlSession tutorials and tested them. Behaviour is the same: resuming works on previos versions of iOS but breaks on 10th. Steps to Reproduce: Download a project form NSUrlSession tutorial https://www.raywenderlich.com

iOS9 - HTTP Connection Error

依然范特西╮ 提交于 2019-11-27 06:00:14
问题 I got 3 error when i update my Xcode 1- App Transport Security has blocked a cleartext HTTP (http://) resource load since it is insecure. Temporary exceptions can be configured via your app's Info.plist file. 2- CFNetwork SSLHandshake failed (-9824) 3- NSURLSession/NSURLConnection HTTP load failed (kCFStreamErrorDomainSSL, -9824) I tried: <key>NSAppTransportSecurity</key> <dict> <key>NSExceptionDomains</key> <dict> <key>yourdomain.com</key> <dict> <!--Include to allow subdomains--> <key