Alamofire.swift completionHandler在调用中缺少参数#2的参数

时间:2015-11-24 06:30:38

标签: swift

我还有两个错误,它们是相同的错误。不知道什么可能是错的。我甚至从源Alamofire doc复制并粘贴,并确保pod是最新的但同样的错误。

public func URLSession(session: NSURLSession, didReceiveChallenge challenge: NSURLAuthenticationChallenge, completionHandler: ((NSURLSessionAuthChallengeDisposition, NSURLCredential?) -> Void)) {
        if sessionDidReceiveChallenge != nil {
            completionHandler(sessionDidReceiveChallenge!(session, challenge)) // Missing argument for parameter #2 in call
        } else {
            completionHandler(.PerformDefaultHandling, nil)
        }
    }

enter image description here

2 个答案:

答案 0 :(得分:1)

从它的外观来看。错误是说您缺少NSURLCredential的值。试试这个。

    completionHandler(sessionDidReceiveChallenge!(session, challenge),nil)

答案 1 :(得分:0)

public func URLSession(session: URLSession, didReceiveChallenge challenge: URLAuthenticationChallenge, completionHandler: ((URLSession.AuthChallengeDisposition, URLCredential?) -> Void)) 
{
    if let serverTrust = challenge.protectionSpace.serverTrust
    {
        completionHandler(.useCredential, URLCredential(trust: serverTrust))
    }
    else 
    { 
        completionHandler(.performDefaultHandling, nil)
    }
}

引用:https://gist.github.com/VadimDez/ea9106ec7d6cf6eb0e58