You will need to implement one of the methods NSURLSessionDelegatein order for it to accept the SSL certificate.
class YourClass: Superclass, NSURLSessionDelegate {
class func loginRemote(successHandler:()->(), errorHandler:(String)->()) {
let session = NSURLSession(configuration: NSURLSessionConfiguration.defaultSessionConfiguration(),
delegate: self,
delegateQueue: nil)
}
func URLSession(session: NSURLSession, task: NSURLSessionTask, didReceiveChallenge challenge: NSURLAuthenticationChallenge, completionHandler: (NSURLSessionAuthChallengeDisposition, NSURLCredential!) -> Void) {
if challenge.protectionSpace.authenticationMethod == NSURLAuthenticationMethodServerTrust {
let credential = NSURLCredential(trust: challenge.protectionSpace.serverTrust)
completionHandler(NSURLSessionAuthChallengeDisposition.UseCredential, credential)
}
}
}
WARNING. This will blindly accept any SSL certificate / connection you are trying to make. This is not a safe practice, but it will allow you to test your server using HTTPS.
source
share