I've had a NSURLSessionDownloadTask that worked perfectly fine for awhile, but today it stopped working and called the func URLSession(session: NSURLSession, didReceiveChallenge challenge: NSURLAuthenticationChallenge, completionHandler: (NSURLSessionAuthChallengeDisposition, NSURLCredential!) -> Void)
method. It seems as thought if I attempt to download the image using SSL, it will attempt a challenge, and if SSL is not used, it works just fine. I'm not sure how to handle this, as I'm not sure what credentials I would provide to the challenge - quite new to networking on iOS. How should I proceed?
func downloadProfilePicture(path: String) {
println("1")
let filePath: NSString = NSString(string: "https://www.domain.com/uploads/\(path).png")
let session = NSURLSession(configuration: .defaultSessionConfiguration(), delegate: self, delegateQueue: nil)
let downloadTask = session.downloadTaskWithURL(NSURL(string: filePath)!)
downloadTask.resume()
println("2")
}
func URLSession(session: NSURLSession, didReceiveChallenge challenge: NSURLAuthenticationChallenge, completionHandler: (NSURLSessionAuthChallengeDisposition, NSURLCredential!) -> Void) {
println("6")
println(challenge.protectionSpace.description)
}
func URLSession(session: NSURLSession, downloadTask: NSURLSessionDownloadTask, didFinishDownloadingToURL location: NSURL) {
println("3")
var image: UIImage = UIImage(data: NSData(contentsOfURL: location)!)!
dispatch_async(dispatch_get_main_queue(), {
self.imageView.image = image
println("4")
})
}
Console:
1
2
6
<NSURLProtectionSpace: 0x7fcc5a4b4ae0>: Host:www.domain.com, Server:https, Auth-Scheme:NSURLAuthenticationMethodServerTrust, Realm:(null), Port:443, Proxy:NO, Proxy-Type:(null)
Note: I haven't changed the settings on my web server for some time, and the SSL certs are still valid.