Files
suixinkan_uikit/suixinkan/UI/Setting/AgreementWebViewController.swift

68 lines
2.0 KiB
Swift
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

//
// AgreementWebViewController.swift
// suixinkan
//
import SnapKit
import UIKit
import WebKit
/// H5 使 WebView
final class AgreementWebViewController: BaseViewController {
private let pageTitle: String
private let url: URL
private let webView = WKWebView(frame: .zero)
private let loadingIndicator = UIActivityIndicatorView(style: .medium)
init(title: String, url: URL) {
pageTitle = title
self.url = url
super.init(nibName: nil, bundle: nil)
}
@available(*, unavailable)
required init?(coder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
override func setupNavigationBar() {
title = pageTitle
}
override func setupUI() {
view.backgroundColor = AppColor.cardBackground
webView.navigationDelegate = self
view.addSubview(webView)
view.addSubview(loadingIndicator)
loadingIndicator.hidesWhenStopped = true
loadingIndicator.startAnimating()
webView.load(URLRequest(url: url))
}
override func setupConstraints() {
webView.snp.makeConstraints { make in
make.edges.equalTo(view.safeAreaLayoutGuide)
}
loadingIndicator.snp.makeConstraints { make in
make.center.equalToSuperview()
}
}
}
extension AgreementWebViewController: WKNavigationDelegate {
func webView(_ webView: WKWebView, didFinish navigation: WKNavigation!) {
loadingIndicator.stopAnimating()
}
func webView(_ webView: WKWebView, didFail navigation: WKNavigation!, withError error: Error) {
loadingIndicator.stopAnimating()
showToast(error.localizedDescription)
}
func webView(_ webView: WKWebView, didFailProvisionalNavigation navigation: WKNavigation!, withError error: Error) {
loadingIndicator.stopAnimating()
showToast(error.localizedDescription)
}
}