Skip to content

Instantly share code, notes, and snippets.

@hardez
Created January 4, 2015 15:53
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hardez/985ce910f82f151b01e2 to your computer and use it in GitHub Desktop.
Save hardez/985ce910f82f151b01e2 to your computer and use it in GitHub Desktop.
NSURLConnectionDelegate
func connection(connection: NSURLConnection, canAuthenticateAgainstProtectionSpace protectionSpace: NSURLProtectionSpace?) -> Bool
{
return protectionSpace?.authenticationMethod == NSURLAuthenticationMethodServerTrust
}
func connection(connection: NSURLConnection, didReceiveAuthenticationChallenge challenge: NSURLAuthenticationChallenge?)
{
if challenge?.protectionSpace.authenticationMethod == NSURLAuthenticationMethodServerTrust
{
if challenge?.protectionSpace.host == "www.myhost.com"
{
let credentials = NSURLCredential(forTrust: challenge!.protectionSpace.serverTrust)
challenge!.sender.useCredential(credentials, forAuthenticationChallenge: challenge)
}
}
challenge?.sender.continueWithoutCredentialForAuthenticationChallenge(challenge)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment