swift - Alamofire not handling Authentication challenge -
utilizing alamofire, im noticing code below isn't being hit breakpoint. make connection, , following error: (error domain=nsurlerrordomain code=-1200 "an ssl error has occurred , secure connection server cannot made." userinfo=0x1741b3f60 {_kcfstreamerrorcodekey=-9806, nslocalizedrecoverysuggestion=would connect server anyway?, nsunderlyingerror=0x17484b8e0 "the operation couldn’t completed. (kcferrordomaincfnetwork error -1200.)", nslocalizeddescription=an ssl error has occurred , secure connection server cannot made.,
func connection(urlrequest:nsurlrequest,rest:restfull?, completion: (anyobject?, nserror?)->void){ let req = request(urlrequest).responsejson(options: .allowfragments) { (_, response, data, error) -> void in if let actualdata: anyobject = data { completion(actualdata, nil) }else { completion(nil, error) } } req.delegate.taskdidreceivechallenge = { session,_, challenge in println("got challenge: \(challenge), in session \(session)") var disposition: nsurlsessionauthchallengedisposition = .usecredential var credential: nsurlcredential = nsurlcredential() if (challenge.protectionspace.authenticationmethod == nsurlauthenticationmethodservertrust){ disposition = nsurlsessionauthchallengedisposition.usecredential credential = nsurlcredential(fortrust: challenge.protectionspace.servertrust!) } return(disposition, credential) } }
you can't set value request class's taskdidreceivechallenge. can use manager class's delegate instead.
manager.sharedinstance.delegate.taskdidreceivechallenge = { session, _, challenge in print("got challenge: \(challenge), in session \(session)") var disposition: nsurlsessionauthchallengedisposition = .usecredential var credential: nsurlcredential = nsurlcredential() if (challenge.protectionspace.authenticationmethod == nsurlauthenticationmethodservertrust){ disposition = nsurlsessionauthchallengedisposition.usecredential credential = nsurlcredential(fortrust: challenge.protectionspace.servertrust!) } return(disposition, credential) }
Comments
Post a Comment