我正在尝试从以下网址加载数据:https://www.sample-videos.com/video/mp4/720/big_buck_bunny_720p_1mb.mp4
功能
func download() {
let configuration = URLSessionConfiguration.default
self.session = URLSession(configuration: configuration, delegate: self, delegateQueue: nil)
self.downloadTask = self.session.dataTask(with: self.url)
self.downloadTask.resume()
}
代表
// NOT GETTING CALLED
func urlSession(_ session: URLSession, task: URLSessionTask, didReceive challenge: URLAuthenticationChallenge, completionHandler: @escaping (URLSession.AuthChallengeDisposition, URLCredential?) -> Void) {
completionHandler(URLSession.AuthChallengeDisposition.useCredential, URLCredential(trust: challenge.protectionSpace.serverTrust!))
}
// NOT GETTING CALLED
func urlSession(_ session: URLSession, didReceive challenge: URLAuthenticationChallenge, completionHandler: @escaping (URLSession.AuthChallengeDisposition, URLCredential?) -> Void) {
completionHandler(URLSession.AuthChallengeDisposition.useCredential, URLCredential(trust: challenge.protectionSpace.serverTrust!))
}
func urlSession(_ session: URLSession, dataTask: URLSessionDataTask, didReceive data: Data) {
self.completion(self, data)
}
func urlSession(_ session: URLSession, task: URLSessionTask, didCompleteWithError error: Error?) {
print(error)
// THIS IS GETTING CALLED WITH ERROR: Could not connect to the server. FULL ERROR BELOW.
}
func urlSession(_ session: URLSession, didBecomeInvalidWithError error: Error?) {
print(error)
}
完全错误
(错误域= NSURLErrorDomain代码= -1004 \“无法连接到 服务器。\“ UserInfo = {NSUnderlyingError = 0x1c0658cc0 {Error Domain = kCFErrorDomainCFNetwork代码= -1004 \“(空)\” UserInfo = {_ kCFStreamErrorCodeKey = 61,_kCFStreamErrorDomainKey = 1}}, NSErrorFailingURLStringKey = https://www.sample-videos.com/video/mp4/720/big_buck_bunny_720p_1mb.mp4, NSErrorFailingURLKey = https://www.sample-videos.com/video/mp4/720/big_buck_bunny_720p_1mb.mp4, _kCFStreamErrorDomainKey = 1,_kCFStreamErrorCodeKey = 61,NSLocalizedDescription =无法连接到服务器。})
以下是ATS配置
任何帮助将不胜感激!
注意:以上网址在Chrome浏览器中有效,但无法在Safari中加载