fix: Trust server in the iOS webview to allow to load the survey package (#5024)

This commit is contained in:
Peter Pesti-Varga
2025-03-23 01:45:53 +01:00
committed by GitHub
parent 6a2a8b74c8
commit d98eb5b46f

View File

@@ -26,6 +26,7 @@ struct SurveyWebView: UIViewRepresentable {
webView.isOpaque = false
webView.backgroundColor = UIColor.clear
webView.isInspectable = true
webView.navigationDelegate = context.coordinator
webView.uiDelegate = context.coordinator
return webView
}
@@ -51,7 +52,7 @@ struct SurveyWebView: UIViewRepresentable {
}
extension SurveyWebView {
class Coordinator: NSObject, WKUIDelegate {
class Coordinator: NSObject, WKUIDelegate, WKNavigationDelegate {
// webView function handles Javascipt alert
func webView(_ webView: WKWebView, runJavaScriptAlertPanelWithMessage message: String, initiatedByFrame frame: WKFrameInfo, completionHandler: @escaping () -> Void) {
let alertController = UIAlertController(title: "", message: message, preferredStyle: .alert)
@@ -59,6 +60,14 @@ extension SurveyWebView {
UIApplication.safeKeyWindow?.rootViewController?.presentedViewController?.present(alertController, animated: true)
completionHandler()
}
func webView(_ webView: WKWebView, didReceive challenge: URLAuthenticationChallenge, completionHandler: @escaping (URLSession.AuthChallengeDisposition, URLCredential?) -> Void) {
if let serverTrust = challenge.protectionSpace.serverTrust {
completionHandler(.useCredential, URLCredential(trust: serverTrust))
} else {
completionHandler(.useCredential, nil)
}
}
}
}