@@ -35,6 +35,9 @@ class ViewController: UIViewController {
3535 @IBAction func onLeftButtonClick( _ sender: Any ) {
3636 if ( webView. canGoBack) {
3737 webView. goBack ( )
38+ } else {
39+ // exit app
40+ UIControl ( ) . sendAction ( #selector( URLSessionTask . suspend) , to: UIApplication . shared, for: nil )
3841 }
3942 }
4043 // open menu in page
@@ -45,7 +48,8 @@ class ViewController: UIViewController {
4548 // Observers for updating UI
4649 override func observeValue( forKeyPath keyPath: String ? , of object: Any ? , change: [ NSKeyValueChangeKey : Any ] ? , context: UnsafeMutableRawPointer ? ) {
4750 if ( keyPath == #keyPath( WKWebView . isLoading) ) {
48- leftButton. isEnabled = webView. canGoBack
51+ // does not fire for PWAs if links are clicked
52+ // leftButton.isEnabled = webView.canGoBack
4953 }
5054 if ( keyPath == #keyPath( WKWebView . estimatedProgress) ) {
5155 progressBar. progress = Float ( webView. estimatedProgress)
@@ -64,6 +68,8 @@ class ViewController: UIViewController {
6468
6569 // settings
6670 webView. allowsBackForwardNavigationGestures = true
71+ webView. configuration. ignoresViewportScaleLimits = false
72+ webView. configuration. preferences. javaScriptEnabled = true
6773 // user agent
6874 if ( useCustomUserAgent) {
6975 webView. customUserAgent = customUserAgent
@@ -89,8 +95,8 @@ class ViewController: UIViewController {
8995 // call after WebView has been initialized
9096 func setupUI( ) {
9197 // UI elements
92- leftButton. isEnabled = false
93- progressBar = UIProgressView ( frame: CGRect ( x: 0 , y: 0 , width: webViewContainer. frame. width, height: 50 ) )
98+ // leftButton.isEnabled = false
99+ progressBar = UIProgressView ( frame: CGRect ( x: 0 , y: 0 , width: webViewContainer. frame. width, height: 40 ) )
94100 progressBar. autoresizingMask = [ . flexibleWidth]
95101 progressBar. progress = 0.0
96102 progressBar. tintColor = progressBarColor
@@ -142,14 +148,6 @@ extension ViewController: WKNavigationDelegate {
142148 alert. addAction ( UIAlertAction ( title: " OK " , style: . default, handler: nil ) )
143149 present ( alert, animated: true , completion: nil )
144150 }
145- // didFail
146- func webView( _ webView: WKWebView , didFail navigation: WKNavigation ! , withError error: Error ) {
147- // show offline screen
148- // @TODO
149- let alert = UIAlertController ( title: " You're offline " , message: " didFail " , preferredStyle: . alert)
150- alert. addAction ( UIAlertAction ( title: " OK " , style: . default, handler: nil ) )
151- present ( alert, animated: true , completion: nil )
152- }
153151}
154152
155153// WebView additional handlers
0 commit comments