nsurlsession

How to cache using NSURLSession and NSURLCache. Not working

五迷三道 提交于 2019-11-27 05:17:41
问题 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 want to add caching. There is no point to me downloading images more than once, b/c of system design, given an image URL I can tell you the content behind that URL will never change. So, now I want to cache the results of my download using apple's built in in-memory/on-disk cache that I've read so

Memory leak when using NSURLSession.downloadTaskWithURL

不羁的心 提交于 2019-11-27 04:23:51
问题 So I hit another roadblock in my endeavors with Swift. I am trying to load multiple images into an image gallery - all works fine except of one thing. The memory use of the application keeps growing and growing despite the fact that I clear the images. After eleminating basically all the code, I found out that this is caused by my image loading script: func loadImageWithIndex(index: Int) { let imageURL = promotions[index].imageURL let url = NSURL(string: imageURL)! let urlSession =

iOS/Cocoa - NSURLSession - Handling Basic HTTPS Authorization

柔情痞子 提交于 2019-11-27 01:22:20
问题 [edited to provide more information] (I'm not using AFNetworking for this project. I may do so in future, but wish to resolve this problem/misunderstanding first.) SERVER SETUP I cannot provide the real service here, but it is a simple, reliable service that returns XML according to a URL such as: https://username:password@example.com/webservice I want to connect to the URL over HTTPS using GET, and determine any authentication failures (http status code 401). I have confirmed that the web

iOS 9 ATS SSL error with supporting server

梦想的初衷 提交于 2019-11-27 00:23:23
问题 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 made. The thing is my server DOES support TLSv1.2 and I'm using NSURLSession . What could be the problem then? 回答1: Apple has released the full requirements list for the App Transport Security. Turned out that we were working with TLS v1.2 but were missing some of the other requirements. Here's the

How do I use NSOperationQueue with NSURLSession?

我是研究僧i 提交于 2019-11-26 22:30:58
问题 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

Function does not wait until the data is downloaded

自闭症网瘾萝莉.ら 提交于 2019-11-26 22:01:37
问题 I have the following function which downloads an image from server; func getImageFromServerById(imageId: String) -> UIImage? { let url:String = "https://dummyUrl.com/\(imageId).jpg" var resultInNSDataformat: NSData! let task = NSURLSession.sharedSession().dataTaskWithURL(NSURL(string: url)!) {(data, response, error) in if (error == nil){ resultInNSDataformat = data } } task.resume() return UIImage(data: resultInNSDataformat) } The function does not wait for the download task to be completed

Uploads using backgroundSessionConfiguration and NSURLSessionUploadTask cause app to crash

北城余情 提交于 2019-11-26 20:47:07
问题 I'm trying out the new fancy iOS 7 background uploading using NSURLSessionUploadTask and it seems to work when I run with defaultSessionConfiguration, but once I try backgroundSessionConfiguration it crashes at the line where I call uploadTaskWithRequest: Here is the code sample below. Oddly, while there are myriad downloadTaskWithRequest examples online, I cannot find a single one that combines background and uploading together. //Create a session w/ background settings

Unexpected Non-Void Return Value In Void Function (Swift 2.0)

自闭症网瘾萝莉.ら 提交于 2019-11-26 20:23:09
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 having an issue with my class that downloads JSON data. I am continually receiving the error Unexpected non-void return value in void function . Here is the code, somewhat truncated, that I am using; ... class func fetchMinionData() -> [Minion] { var myURL = "http://myurl/test.json" let dataURL = NSURL(string: myURL) let request = NSURLRequest(URL: dataURL!, cachePolicy:

iOS 9.3 : An SSL error has occurred and a secure connection to the server cannot be made

我只是一个虾纸丫 提交于 2019-11-26 19:41:06
问题 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 web-services for one of my demo app with iOS 9.3 XCode 7.3 Swift 2.2 Alamofire 3.3.0 and Local server : https://filename.hostname.net Note: before assuming its Duplicate, I would request please read it all the way,even same i have reported to apple dev forums Using Alamofire Library func

How To Download Multiple Files Sequentially using NSURLSession downloadTask in Swift

為{幸葍}努か 提交于 2019-11-26 18:42:20
I have an app that has to download multiple large files. I want it to download each file one by one sequentially instead of concurrently. When it runs concurrently the app gets overloaded and crashes. So. Im trying to wrap a downloadTaskWithURL inside a NSBlockOperation and then setting the maxConcurrentOperationCount = 1 on the queue. I wrote this code below but it didnt work since both files get downloaded concurrently. import UIKit class ViewController: UIViewController, NSURLSessionDelegate, NSURLSessionDownloadDelegate { override func viewDidLoad() { super.viewDidLoad() // Do any