Skip to content

Instantly share code, notes, and snippets.

@pay-napster-x
Created June 2, 2020 02:25
Show Gist options
  • Save pay-napster-x/6fd5b4b47496dffc21a14a4be009850b to your computer and use it in GitHub Desktop.
Save pay-napster-x/6fd5b4b47496dffc21a14a4be009850b to your computer and use it in GitHub Desktop.
WKWebView Configure.
private func configWebView() {
guard webView == nil else { return }
let config = WKWebViewConfiguration()
config.userContentController.add(WebKitLeakAvoider(delegate: self), name: CashfeedWebUtil.JavaScriptMessage.getPost)
config.userContentController.add(WebKitLeakAvoider(delegate: self), name: CashfeedWebUtil.JavaScriptMessage.getUserInfo)
config.userContentController.add(WebKitLeakAvoider(delegate: self), name: CashfeedWebUtil.JavaScriptMessage.getDeviceInfo)
config.setURLSchemeHandler(UploadWKSchemeHandler(), forURLScheme: PreviewViewModel.uploadURLScheme)
config.allowsInlineMediaPlayback = true
config.mediaTypesRequiringUserActionForPlayback = .audio
webView = WKWebView(frame: view.bounds, configuration: config)
webView.scrollView.bounces = false
webView.scrollView.alwaysBounceVertical = false
webView.translatesAutoresizingMaskIntoConstraints = false
webView.isOpaque = false
webView.backgroundColor = .white
view.addSubview(webView)
NSLayoutConstraint
.activate([webView.topAnchor.constraint(equalTo: view.safeAreaLayoutGuide.topAnchor),
webView.leadingAnchor.constraint(equalTo: view.leadingAnchor),
webView.trailingAnchor.constraint(equalTo: view.trailingAnchor),
webView.bottomAnchor.constraint(equalTo: view.bottomAnchor)])
previewViewModel.webRequest()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment