![](/img/trans.png)
[英]Type '[NSObject : AnyObject]!' does not conform to protocol 'DictionaryLiteralConvertible'
[英]Swift3: Type 'NSObject' does not conform to protocol 'URLAuthenticationChallengeSender'
在Swift3中,“ NSURLAuthenticationChallengeSender”已更改为“ URLAuthenticationChallengeSender”,因此在委托方法中,其方法也从NSURlAuthentication更改为URLAuthentication(自动Xcode编辑)
我很困惑我是否仍然缺少任何委托方法,但包括所有下面的委托方法仍然显示如上错误。
如果有人遇到相同的问题,请您帮忙!!!
迅捷3
class GeneralFunctions: NSObject,NSURLConnectionDataDelegate,URLAuthenticationChallengeSender {
}
委托方法
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
}
因此,在Swift 3中,某些方法的签名已略有变化。 我也面临这个问题。 对于所有必需的委托方法,只需开始输入该方法的前几个字母,然后按ctrl +空格,它将自动完成该方法的正确签名
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.