Skip to content

Commit 904c8f5

Browse files
committed
fixed back button always disabled for PWAs, cleaned up colors
1 parent 5466789 commit 904c8f5

File tree

4 files changed

+35
-23
lines changed

4 files changed

+35
-23
lines changed

ios-pwa-wrapper.xcodeproj/xcuserdata/kzb.xcuserdatad/xcschemes/xcschememanagement.plist

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,23 @@
1010
<integer>0</integer>
1111
</dict>
1212
</dict>
13+
<key>SuppressBuildableAutocreation</key>
14+
<dict>
15+
<key>2D504BEA1FA100E20019B279</key>
16+
<dict>
17+
<key>primary</key>
18+
<true/>
19+
</dict>
20+
<key>2D504C011FA100E20019B279</key>
21+
<dict>
22+
<key>primary</key>
23+
<true/>
24+
</dict>
25+
<key>2D504C0C1FA100E20019B279</key>
26+
<dict>
27+
<key>primary</key>
28+
<true/>
29+
</dict>
30+
</dict>
1331
</dict>
1432
</plist>

ios-pwa-wrapper/AppDelegate.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
1919
// Override point for customization after application launch.
2020

2121
// Change Navigation style
22-
UINavigationBar.appearance().barTintColor = primaryColor
22+
UINavigationBar.appearance().barTintColor = navigationBarColor
2323
UINavigationBar.appearance().titleTextAttributes = [NSAttributedStringKey.foregroundColor: navigationTitleColor]
2424
UINavigationBar.appearance().largeTitleTextAttributes = [NSAttributedStringKey.foregroundColor: navigationTitleColor]
2525
UIBarButtonItem.appearance().tintColor = navigationButtonColor

ios-pwa-wrapper/Constants.swift

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,34 +6,30 @@
66
// Copyright © 2017 Martin Kainzbauer. All rights reserved.
77
//
88

9-
//import Foundation
109
import UIKit
1110

1211
// Basic App-/WebView-configuration
1312
let appTitle = "iOS PWA Wrapper"
14-
let webAppUrl = URL(string: "https://www.duckduckgo.com")
15-
let allowedOrigin = "duckduckgo.com"
13+
let webAppUrl = URL(string: "https://www.leasingrechnen.at")
14+
let allowedOrigin = "leasingrechnen.at"
1615
let menuButtonJavascript = """
17-
document.querySelector('body').remove();
16+
$('.button-collapse').sideNav('show');
1817
"""
1918
let useCustomUserAgent = false
2019
let useUserAgentPostfix = true
21-
let customUserAgent = "Mozilla/5.0 (iPhone; CPU iPhone OS 11_0 like Mac OS X) AppleWebKit/604.1.38 (KHTML, like Gecko) Version/11.0 Mobile/15A356"
20+
let customUserAgent = "Mozilla/5.0 (iPhone; CPU iPhone OS 11_0_1 like Mac OS X) AppleWebKit/604.2.10 (KHTML, like Gecko) Mobile/15A8401"
2221
let userAgentPostfix = "iOSApp"
2322

24-
2523
// Settings
2624
let changeAppTitleToPageTitle = false
2725
let forceLargeTitle = false
2826

29-
// Colors
27+
// Colors & Styles
3028
let useLightStatusBarStyle = true
31-
let primaryColor = getColorFromHex(hex: 0xF44336, alpha: 1.0)
32-
let primaryColorDark = getColorFromHex(hex: 0xD32F2F, alpha: 1.0)
33-
let primaryColorLight = getColorFromHex(hex: 0xE57373, alpha: 1.0)
34-
let progressBarColor = getColorFromHex(hex: 0x4CAF50, alpha: 1.0)
29+
let navigationBarColor = getColorFromHex(hex: 0xF44336, alpha: 1.0)
3530
let navigationButtonColor = getColorFromHex(hex: 0xFFFFFF, alpha: 1.0)
3631
let navigationTitleColor = getColorFromHex(hex: 0xFFFFFF, alpha: 1.0)
32+
let progressBarColor = getColorFromHex(hex: 0x4CAF50, alpha: 1.0)
3733

3834
// Color Helper function
3935
func getColorFromHex(hex: UInt, alpha: CGFloat) -> UIColor {

ios-pwa-wrapper/ViewController.swift

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)