ios - NSURLSession didReceiveChallenge is not being call for error (kCFStreamErrorDomainSSL, -9813) -
i trying make nsurlsession request , kept getting error (kcfstreamerrordomainssl, -9813), below code -
let urlpath = "https://myurl" func jsonparser() { guard let endpoint = nsurl(string: urlpath) else { print("error creating endpoint") return } let request = nsmutableurlrequest(url:endpoint) nsurlsession.sharedsession().datataskwithrequest(request) { (data, response, error) in { guard let data = data else { throw jsonerror.nodata } guard let json = try nsjsonserialization.jsonobjectwithdata(data, options: []) as? nsdictionary else { throw jsonerror.conversionfailed } print(json) } catch let error jsonerror { print(error.rawvalue) } catch let error nserror { print(error.debugdescription) } }.resume() }
to resolve error added code, somehow below code not called , still getting same error -
func urlsession(session: nsurlsession, didreceivechallenge challenge: nsurlauthenticationchallenge, completionhandler: (nsurlsessionauthchallengedisposition, nsurlcredential?) -> void) { if let xmturl = urlpath, xmthost = xmturl.host { if challenge.protectionspace.authenticationmethod == nsurlauthenticationmethodservertrust && challenge.protectionspace.host == xmthost { let mycredential = nsurlcredential(trust: challenge.protectionspace.servertrust!) completionhandler(nsurlsessionauthchallengedisposition.usecredential, mycredential) } } }
please help. thanks!
Comments
Post a Comment