-1
WKWebView 기반 iOS 응용 프로그램에 대한 문제점이 있습니다. 페이지의 일부 링크를 클릭 할 수 없습니다. 사파리 뷰 컨트롤러를 사용해 보았을 때, 그들은 작동합니다. 누구든지 나를 도울 수 있습니까?일부 WKWebView 링크를 클릭 할 수 없음
이 내 소스 코드 :
import UIKit
import WebKit
class ViewController: UIViewController, WKUIDelegate, WKNavigationDelegate {
var webView: WKWebView! //declare the webview has to be optional
var activityIndicator: UIActivityIndicatorView!
override func loadView() {
super.loadView()
let webConfiguration = WKWebViewConfiguration()
webView = WKWebView(frame: .zero, configuration: webConfiguration)
webView.uiDelegate = self
webView.navigationDelegate = self
view = webView
}
override func viewDidLoad() {
super.viewDidLoad()
let myURL = URL(string: "https://stolenandfound.com/")
let myRequest = URLRequest(url: myURL!)
webView.load(myRequest)
activityIndicator = UIActivityIndicatorView() //declare the progress indicator
activityIndicator.frame = CGRect(x: 0, y: 0, width: 50, height: 50)
self.activityIndicator.center = CGPoint(x:self.view.bounds.size.width/2.0,y: self.view.bounds.size.height/2.0);
activityIndicator.autoresizingMask = (UIViewAutoresizing(rawValue: UIViewAutoresizing.RawValue(UInt8(UIViewAutoresizing.flexibleRightMargin.rawValue) | UInt8(UIViewAutoresizing.flexibleLeftMargin.rawValue) | UInt8(UIViewAutoresizing.flexibleBottomMargin.rawValue) | UInt8(UIViewAutoresizing.flexibleTopMargin.rawValue))))
//activityIndicator.center = CGPoint(x: UIScreen.main.bounds.size.width/2, y: UIScreen.main.bounds.size.height/2)
activityIndicator.hidesWhenStopped = true
activityIndicator.activityIndicatorViewStyle = UIActivityIndicatorViewStyle.whiteLarge
activityIndicator.color = UIColor.darkGray
self.view.addSubview(activityIndicator)
}
func webView(_ webView: WKWebView, didStartProvisionalNavigation navigation: WKNavigation!) {
activityIndicator.startAnimating()
}
func webView(_ webView: WKWebView, didFailProvisionalNavigation navigation: WKNavigation!, withError error: Error) {
print("it is an error")
activityIndicator.stopAnimating()
let alert = UIAlertController(title: "Network Error", message: "You have no internet coonection", preferredStyle: .alert)
let restartAction = UIAlertAction(title: "Reload page", style: .default, handler: { (UIAlertAction) in
self.viewDidLoad()
})
alert.addAction(restartAction)
present(alert, animated: true, completion: nil)
}
func webView(_ webView: WKWebView, didFinish navigation: WKNavigation!) {
activityIndicator.stopAnimating()
}
@IBAction func backButton(_ sender: UIBarButtonItem) {
webView.goBack()
}
@IBAction func refreshButton(_ sender: UIBarButtonItem) {
webView.reload()
}
}