我有weburl,我转换了iOS应用程序(通过在webview中打开该URL)。我必须从webview下载pdf。当我点击下载时,我最终将登录html页面下载为文档目录中的tmp文件。
我假设它没有下载pdf,因为我们正在创建新会话。我不知道该怎么办?
尝试下面但现在正在工作
let username = "sss@gmail.com"
let password = "test"
let loginString = String(format: "%@:%@", username, password)
let loginData = loginString.data(using: String.Encoding.utf8)!
let base64LoginString = loginData.base64EncodedString()
var newReq = navigationAction.request
newReq.setValue("Basic \(base64LoginString)", forHTTPHeaderField: "Authorization")
let task = DownloadManager.shared.activate().dataTask(with: navigationAction.request)
task.resume()
2。尝试认证delgate但现在正在调用
func urlSession(_ session: URLSession,
task: URLSessionTask,
didReceive challenge: URLAuthenticationChallenge,
completionHandler: @escaping (URLSession.AuthChallengeDisposition, URLCredential?) -> Void) {
completionHandler(URLSession.AuthChallengeDisposition.useCredential, URLCredential(user: "sss@gmail.com", password: "test", persistence: URLCredential.Persistence.none))
debugPrint("Challenge: \(task)")
}
任何想法?