ios - Error with URLsession delegate function -
i trying make ssl connection urlsession delegate , error message get:
objective-c method 'urlsession:didreceivechallenge:completionhandler:' provided method 'urlsession(:didreceivechallenge:completionhandler:)' conflicts optional requirement method 'urlsession(:didreceivechallenge:completionhandler:)' in protocol 'nsurlsessiondelegate'
func urlsession(session: nsurlsession, didreceivechallenge challenge: nsurlauthenticationchallenge, completionhandler: (nsurlsessionauthchallengedisposition, nsurlcredential!) -> void) { let servertrust: sectrustref = challenge.protectionspace.servertrust! let servercert: seccertificateref = sectrustgetcertificateatindex(servertrust, 0).takeunretainedvalue() let serverkey: nsdata = seccertificatecopydata(servercert).takeretainedvalue() let bundle: nsbundle = nsbundle.mainbundle() let mainbun = bundle.pathforresource("ca", oftype: "der") let key: nsdata = nsdata(contentsoffile: mainbun!)! // let turntocert: seccertificateref = // seccertificatecreatewithdata(kcfallocatordefault, key).takeretainedvalue() if serverkey == key { let credential = nsurlcredential(fortrust: challenge.protectionspace.servertrust!) challenge.sender!.usecredential(credential, forauthenticationchallenge: challenge) completionhandler(nsurlsessionauthchallengedisposition.usecredential,credential) } else{ challenge.sender!.cancelauthenticationchallenge(challenge) completionhandler(nsurlsessionauthchallengedisposition.cancelauthenticationchallenge, nil) } } func urlsession(session: nsurlsession, task: nsurlsessiontask, willperformhttpredirection response: nshttpurlresponse, newrequest request: nsurlrequest, completionhandler: (nsurlrequest!) -> void) { var newrequest : nsurlrequest? = request print(newrequest?.description); completionhandler(newrequest) }
do use swift 2 now? started getting error when updating swift 2.
i solve changing to:
func urlsession(session: nsurlsession, task: nsurlsessiontask, didreceivechallenge challenge: nsurlauthenticationchallenge, completionhandler: (nsurlsessionauthchallengedisposition, nsurlcredential?) -> void) { // code }
Comments
Post a Comment