     }
     
     public func urlSession(_ session: URLSession, didReceive challenge: URLAuthenticationChallenge, completionHandler: (URLSession.AuthChallengeDisposition, URLCredential?) -> Swift.Void){
-        //        if (challengeHandler != nil) {
-        //            challengeHandler?(challenge: challenge,completionHandler: completionHandler)
-        //        }
-        /*
-         public typealias challengeHandler = (challenge: URLAuthenticationChallenge, completionHandler: (URLSession.AuthChallengeDisposition, URLCredential?) -> Swift.Void)
-         */
-        //        if let handler:challengeHandler = challengeHandler{
-        //            handler(challenge:challenge,completionHandler:)
-        //        }
-        
-        
-        
-        let disposition: Foundation.URLSession.AuthChallengeDisposition = .performDefaultHandling
+        
+        var disposition: Foundation.URLSession.AuthChallengeDisposition = .performDefaultHandling
         var credential:URLCredential? = self.credential
-        //1.认证方法是服务端信任
-        if challenge.protectionSpace.authenticationMethod == NSURLAuthenticationMethodServerTrust {
+        
+        if let handler:challengeHandler = challengeHandler {
+            
+            (disposition, credential) = handler(session, challenge)
+            
+        } else if challenge.protectionSpace.authenticationMethod == NSURLAuthenticationMethodServerTrust {
+            //1.认证方法是服务端信任
+            
             //2.如果服务端信任存在
             if let serverTrust = challenge.protectionSpace.serverTrust {
                 //3.验证服务端的信任
-                if self.trustIsValid(serverTrust) {
+                if WTURLSessionDelegate.trustIsValid(serverTrust) {
                     //4.如果验证成功了,使用服务端的信任创建凭据
                     credential = URLCredential(trust: serverTrust)
                 }

    
    public var progressHandler:progressHandler?
    public var response:URLResponse?
    
    
    //懒加载,需要的时候创建对象
    public lazy var data:Data = Data()

        
    }
    
    static func trustIsValid(_ trust:SecTrust) -> Bool {
        var isValid = false
        
        var result = SecTrustResultType.invalid
