简体   繁体   English

Swift3:类型“ NSObject”不符合协议“ URLAuthenticationChallengeSender”

[英]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.

相关问题 输入'[NSObject:AnyObject]!' 不符合协议'DictionaryLiteralConvertible' - Type '[NSObject : AnyObject]!' does not conform to protocol 'DictionaryLiteralConvertible' 类型不符合协议Swift - Type does not conform to protocol Swift Swift - 类型“*”不符合协议“*” - Swift - Type '*' does not conform to protocol '*' Swift3错误:类型“ NSFastEnumerationIterator.Element”(又名“ Any”)不符合协议“ AnyObject” - Swift3 error : Type 'NSFastEnumerationIterator.Element' (aka 'Any') does not conform to protocol 'AnyObject' 类型不符合协议序列类型 - Swift - type does not conform to protocol Sequence Type - Swift 类型“NSPersistentStore”在swift中不符合协议“BooleanType” - Type 'NSPersistentStore' does not conform to protocol 'BooleanType' in swift Swift:类型'ViewController'不符合协议'UIPageViewControllerDataSource' - Swift: Type 'ViewController' does not conform to protocol 'UIPageViewControllerDataSource' Swift 2.0类型'()'不符合协议 - Swift 2.0 Type '()' does not conform to protocol Swift:`类型'[String]'不符合协议'StringLiteralConvertible' - Swift: `Type '[String]' does not conform to protocol 'StringLiteralConvertible'` 类型“myViewController”不符合Swift中的协议UIPIckerDataSource - Type “myViewController” does not conform to protocol UIPIckerDataSource in Swift
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM