I\'m using Xcode 7, Swift 2, and iOS9. I want to connect to a web service using NSURLSession but I get the following error when I try to connect:
2015-10-13
I received the error "The certificate for this server is invalid. You might be connecting to a server that is pretending to be "www.yoururl.com" which could put your confidential information at risk."
I solved this by having doing this in my httpclient file. The following code will ignore the authentication request completely.
var session: URLSession?
session = URLSession(configuration: sessionConfiguration(), delegate: self, delegateQueue: nil)
private func urlSession(_ session: URLSession, didReceive challenge: URLAuthenticationChallenge, completionHandler: (URLSession.AuthChallengeDisposition) -> Void) {
completionHandler(
.cancelAuthenticationChallenge
)
}
Also not sure if it impacted the above but In my info.plist I had "Allow Transport Security Settings" & the child key-value option "Allow Arbitrary Loads" which I set to YES.