Created
January 9, 2024 20:31
-
-
Save knight6700/1613c57bc31496ec285a4b184b16e1c9 to your computer and use it in GitHub Desktop.
handle a webView
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@IBOutlet var containerStack: UIStackView! | |
func webView( | |
_ webView: WKWebView, | |
createWebViewWith configuration: WKWebViewConfiguration, | |
for navigationAction: WKNavigationAction, | |
windowFeatures: WKWindowFeatures | |
) -> WKWebView? { | |
if navigationAction.targetFrame == nil { | |
let tempURL = navigationAction.request.url | |
var components = URLComponents() | |
components.scheme = tempURL?.scheme | |
components.host = tempURL?.host | |
components.path = (tempURL?.path)! | |
if !(components.url?.absoluteString.isEmpty ?? false) { | |
let webViewtemp = WKWebView(frame: view.bounds, configuration: configuration) | |
webViewtemp.uiDelegate = self | |
if #available(iOS 16.4, *) { | |
webViewtemp.isInspectable = true | |
} | |
webViewtemp.navigationDelegate = self | |
containerStack.arrangedSubviews[0].isHidden = true | |
containerStack.addArrangedSubview(webViewtemp) | |
return webViewtemp | |
} else { | |
webView.load(navigationAction.request) | |
} | |
} | |
return nil | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment