Skip to content

Instantly share code, notes, and snippets.

@VadimDez
Last active August 29, 2015 14:21
Show Gist options
  • Save VadimDez/ea9106ec7d6cf6eb0e58 to your computer and use it in GitHub Desktop.
Save VadimDez/ea9106ec7d6cf6eb0e58 to your computer and use it in GitHub Desktop.
Alamofire accept self signed certificates, override URLSession function in Manager.swift
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