Post

Replies

Boosts

Views

Activity

WKWebView Authorization Challenge fails to refresh
I have a url that I want to stream, the stream is protected by basic auth. I am using URLAuthenticationChallenge (wkwebview navigation delegate function) method to provide my credentials. the credential changes with every stream url. The issue I am facing is that URLAuthenticationChallenge is never called upon refresh or on new URL request until the app is killed and opened again. I have tried: clearing cooking setting cache to ignore opening an another blank url using child view approach setting wkwebview instance to nil I always end up with 401 in decidePolicy (wkwebview delegate functions) on subsequent refresh call. Upon inspecting I see that it is using my previous used credentials and never calling challenge to update. *Backend has a no-cache policy in its header. **I am using http resource, the aim is to have streaming service on iOS. class ViewController: UIViewController, WKNavigationDelegate, WKUIDelegate { @IBOutlet weak var wkWebView: WKWebView! override func viewDidLoad() { super.viewDidLoad() let url = URL(string: "http://some-ip-address/some-path")! var request = URLRequest(url: url) request.httpMethod = "GET" wkWebView.configuration.allowsInlineMediaPlayback = true wkWebView.navigationDelegate = self wkWebView.load(request) } // this is just called once. we want to call it everytime our page refreshes. // we have tried clearing cache and cookies but failed to call challenge func webView(_ webView: WKWebView, didReceive challenge: URLAuthenticationChallenge, completionHandler: @escaping(URLSession.AuthChallengeDisposition, URLCredential?) -> Void) { let credential = URLCredential(user: "user", password: "password", persistence: .forSession) completionHandler(.useCredential, credential) } }
1
0
246
Nov ’24