nsurlsessiondatatask

Is there a way to request multiple distinct resources in parallel using URLSession.shared.dataTask

有些话、适合烂在心里 提交于 2019-12-04 18:33:12
I found this piece of code here on how to download images simultaneously without any breakages, func loadImageRobsAnswer(with urlString: String?) { // cancel prior task, if any weak var oldTask = currentTask currentTask = nil oldTask?.cancel() // reset imageview's image self.image = nil // allow supplying of `nil` to remove old image and then return immediately guard let urlString = urlString else { return } // check cache if let cachedImage = DataCache.shared.object(forKey: urlString) { self.transition(toImage: cachedImage as? UIImage) //self.image = cachedImage return } // download let url =

NSURLSessionTask authentication challenge completionHandler and NSURLAuthenticationChallenge client

为君一笑 提交于 2019-12-04 09:34:13
I am implementing a custom NSURLProtocol , and internally want to use NSURLSession with data tasks for internal networking instead of NSURLConnection . I have hit an interesting problem and wonder about the internal implementation of the challenge handler of NSURLSession / NSURLSessionTask . - (void)URLSession:(NSURLSession *)session task:(NSURLSessionTask *)task didReceiveChallenge:(NSURLAuthenticationChallenge *)challenge completionHandler:(void (^)(NSURLSessionAuthChallengeDisposition disposition, NSURLCredential *credential))completionHandler; Here I am basically provided with two

How to sync serial queue for URLSession tasks?

泄露秘密 提交于 2019-12-04 07:04:50
Using XCode-8.2.1, Swift-3.0.2 and iOS-10.2.1, I am trying to call two different URLSession.shared.dataTasks (the first is a simple URL-request and the second is a POST-request). Since my first dataTask delivers a result that is needed in the httpBody of the second dataTask, the two URLSession.shared.dataTasks shall run in series, one after the other! (and also the preparative code shall run consecutively). I tried, so far, using two consecutive serialQueue.sync{} queues. But I had to realize that the code does not perform in the order I would like to. The print-statement in the log turn out