2016-09-22 12 views
0

デリゲートメソッドでもNSURlAuthenticationからURLAuthenticationに変更するように、「URLAuthenticationChallengeSender」に変更(自動Xcodeのは、編集)Swift3:タイプ「NSObjectのは」プロトコルに準拠していない「URLAuthenticationChallengeSender」Swift3「NSURLAuthenticationChallengeSender」は、

私は混乱して天気をしています私はまだ任意のデリゲートメソッドが欠けているが、下のすべての委任されたメソッドを含む上記のようにエラーを表示します。

同じ問題に直面している人がいる場合は、この手伝いをしてください。

Swift3

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 
} 
+0

デリゲートメソッドの正しいパラメータを実装していることを確認してください。エラー:NSErrorからchatngeになることがあります。エラー:エラー? – JVS

+0

はい、swift3 !!!!のように多くの変更がありますもう一度@JVSをチェックしてください – Sanju

+0

'NSURLConnection'ではなく' URLConnection'を使用することは可能でしょうか? – BallpointBen

答えて

0

のでスウィフト3少し変更されている方法のいくつかのシグネチャを持ちます。私もこの問題に直面しました。すべての必要なデリゲートメソッドについては、メソッドの最初の数文字を入力してからctrl + spaceを押すと、メソッドの正しいシグニチャに自動補完されます。

関連する問題