[英]Swift3: Type 'NSObject' does not conform to protocol 'URLAuthenticationChallengeSender'
In Swift3 'NSURLAuthenticationChallengeSender' changed to 'URLAuthenticationChallengeSender' so in delegate methods also change from NSURlAuthentication to URLAuthentication(Auto Xcode edits) 在Swift3中,“ NSURLAuthenticationChallengeSender”已更改为“ URLAuthenticationChallengeSender”,因此在委托方法中,其方法也从NSURlAuthentication更改为URLAuthentication(自动Xcode编辑)
I am confused wether i am missing still any delegate methods but included all below delegated methods still it shows error as above . 我很困惑我是否仍然缺少任何委托方法,但包括所有下面的委托方法仍然显示如上错误。
If any one facing the same issue can you please help in this!!! 如果有人遇到相同的问题,请您帮忙!!!
Swift3 迅捷3
class GeneralFunctions: NSObject,NSURLConnectionDataDelegate,URLAuthenticationChallengeSender {
}
Delegate Methods 委托方法
func connection(connection: NSURLConnection, willSendRequestForAuthenticationChallenge challenge: URLAuthenticationChallenge) {
}
func connection(connection: NSURLConnection, didReceiveResponse:URLResponse)
{
}
func connection(connection: NSURLConnection, didReceiveData data: NSData) {
}
func connection(connection: NSURLConnection, didFailWithError error: NSError) {
print("Connection Failed")
}
func connection(connection: NSURLConnection, didReceiveAuthenticationChallenge challenge: URLAuthenticationChallenge) {
//sanju swift3 160922-- re verify
// let myCredential = URLCredential(forTrust: challenge.protectionSpace.serverTrust!)
// challenge.sender!.useCredential(myCredential, forAuthenticationChallenge: challenge)
}
func connection(connection: NSURLConnection, canAuthenticateAgainstProtectionSpace protectionSpace: URLProtectionSpace) -> Bool {
return true
}
func URLSession(session: URLSession, didReceiveChallenge challenge: URLAuthenticationChallenge, completionHandler: (URLSession.AuthChallengeDisposition, URLCredential) -> Void) {
let protectionSpace = challenge.protectionSpace
let theSender = challenge.sender
if protectionSpace.authenticationMethod == NSURLAuthenticationMethodServerTrust {
if let theTrust = protectionSpace.serverTrust{
let theCredential = URLCredential(trust: theTrust)
theSender?.use(theCredential, for: challenge)
return
}
}
theSender?.performDefaultHandling!(for: challenge)
return
}
So with Swift 3 the signature of some of the methods have slightly changed. 因此,在Swift 3中,某些方法的签名已略有变化。 I faced this issue too. 我也面临这个问题。 For all your required delegate methods just start typing the first few letters of the method then press ctrl + space and it should autocomplete you to the correct signature of the method 对于所有必需的委托方法,只需开始输入该方法的前几个字母,然后按ctrl +空格,它将自动完成该方法的正确签名
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.