Swift, SSL Self Signed certificate IOS8+ -


i want implement ssl in webservice call. having error below:

nsurlconnection/cfurlconnection http load failed (kcfstreamerrordomainssl, -9813)

my code below

func checknetworkconnection(callback: ((isconnected: bool) -> void)!) {     var checknetworkurl: string = “testurl”     var request = nsmutableurlrequest(url: nsurl(string: checknetworkurl)!)      request.httpmethod = "post"     request.addvalue("application/xml", forhttpheaderfield: "content-type")     request.addvalue("application/xml", forhttpheaderfield: "accept")     request.timeoutinterval = 20000.0      var response: nsurlresponse?     var error: nserror?     var data = nsurlconnection.sendsynchronousrequest(request, returningresponse: &response, error: &error)           if error == nil{              if data != nil{                  self.parser.getloginresultdatadictionary(data!) {(datadictionary) -> void in                     if let datadict = datadictionary[self.constants.defaultskeys.response_result] as? dictionary<string,string>                     {                         if let status: anyobject  = datadict[self.constants.defaultskeys.response_status] {                             if status as! string == self.constants.defaultskeys.response_success {                                 callback(isconnected:  true)                             }                             else{                                 callback(isconnected:  false)                             }                         }                         else{                             callback(isconnected:  false)                         }                     }                     else{                         callback(isconnected:  false)                     }                 }             }             else{                 callback(isconnected:  false)             }         }         else{             callback(isconnected:  false)         }     //}      } 

method added

   public func connection(connection: nsurlconnection,  willsendrequestforauthenticationchallenge challenge: nsurlauthenticationchallenge) {     challenge.sender.usecredential(nsurlcredential(fortrust: challenge.protectionspace.servertrust), forauthenticationchallenge: challenge)     challenge.sender.continuewithoutcredentialforauthenticationchallenge(challenge) } 

added delegate below

public class networkutil : nsobject, nsurlconnectiondelegate { }

how can configure ssl in above code?

thanks,

as far know way implement nsurlconnectiondelegate method:

func connection(connection: nsurlconnection, willsendrequestforauthenticationchallenge challenge: nsurlauthenticationchallenge) {     challenge.sender.usecredential(nsurlcredential(fortrust: challenge.protectionspace.servertrust), forauthenticationchallenge: challenge)     challenge.sender.continuewithoutcredentialforauthenticationchallenge(challenge) } 

and if targeting older versions, gonna need canauthenticateagainstprotectionspace method, deprecated since ios8.


Comments

Popular posts from this blog

mysql - FireDac error 314 - but DLLs are in program directory -

git - How to list all releases of public repository with GitHub API V3 -

c++ - Getting C2512 "no default constructor" for `ClassA` error on the first parentheses of constructor for `ClassB`? -