Last active
August 29, 2015 14:21
-
-
Save VadimDez/ea9106ec7d6cf6eb0e58 to your computer and use it in GitHub Desktop.
Alamofire accept self signed certificates, override URLSession function in Manager.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public func URLSession(session: NSURLSession, task: NSURLSessionTask, didReceiveChallenge challenge: NSURLAuthenticationChallenge, completionHandler: ((NSURLSessionAuthChallengeDisposition, NSURLCredential!) -> Void)) { | |
//TODO: Remove this | |
if challenge.protectionSpace.authenticationMethod == NSURLAuthenticationMethodServerTrust { | |
let trustedDomain = "self.signed.domain.com" | |
if challenge.protectionSpace.host == trustedDomain { | |
let trustedCredential = NSURLCredential(forTrust: challenge.protectionSpace.serverTrust) | |
completionHandler(.UseCredential, trustedCredential) | |
return | |
} | |
} | |
//TODO: No, Really Remove This | |
if taskDidReceiveChallenge != nil { | |
completionHandler(taskDidReceiveChallenge!(session, task, challenge)) | |
} else if let delegate = self[task] { | |
delegate.URLSession(session, task: task, didReceiveChallenge: challenge, completionHandler: completionHandler) | |
} else { | |
URLSession(session, didReceiveChallenge: challenge, completionHandler: completionHandler) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment