I want to embed a website to my app with wkwebview using SwiftUI. Web that I want to use has basic auth prompt credential. I have tried with this code. But the web site still show unauthorized credential.
let url: String
func makeUIView(context: Context) -> WKWebView {
guard let url = URL(string: self.url) else {
return WKWebView()
}
let request = URLRequest(url: url)
let webView = WKWebView()
webView.load(request)
return webView
}
func updateUIView(_ webView: WKWebView, context: UIViewRepresentableContext<WebEmbed>) {
}
func webView(_ webView: WKWebView, didReceive challenge: URLAuthenticationChallenge, completionHandler: @escaping (URLSession.AuthChallengeDisposition, URLCredential?) -> Void) {
let username = HelperController().getSession().username
let password = HelperController().getSession().password
let credential = URLCredential(user: username, password: password, persistence: URLCredential.Persistence.forSession)
challenge.sender?.use(credential, for: challenge)
completionHandler(URLSession.AuthChallengeDisposition.useCredential, credential)
}
this is the result of the embed of the website which unauthorized
I have checked on the terminal but there is no error. Is there any solution how to fix the credential so can be passed to the website embedded?