@@ -59,19 +59,34 @@ class ViewController: UIViewController {
5959 webView = WKWebView ( frame: CGRect ( x: 0 , y: 0 , width: webViewContainer. frame. width, height: webViewContainer. frame. height) )
6060 webView. navigationDelegate = self
6161 webView. uiDelegate = self
62- webViewContainer. addSubview ( webView)
6362 webView. autoresizingMask = [ . flexibleWidth, . flexibleHeight]
63+ webViewContainer. addSubview ( webView)
6464
6565 // settings
6666 webView. allowsBackForwardNavigationGestures = true
67+ // user agent
68+ if ( useCustomUserAgent) {
69+ webView. customUserAgent = customUserAgent
70+ }
71+ if ( useUserAgentPostfix) {
72+ if ( useCustomUserAgent) {
73+ webView. customUserAgent = customUserAgent + " " + userAgentPostfix
74+ } else {
75+ webView. evaluateJavaScript ( " navigator.userAgent " , completionHandler: { ( result, error) in
76+ if let resultObject = result {
77+ self . webView. customUserAgent = ( String ( describing: resultObject) + " " + userAgentPostfix)
78+ }
79+ } )
80+ }
81+ }
6782
6883 // init observers
6984 webView. addObserver ( self , forKeyPath: #keyPath( WKWebView . isLoading) , options: NSKeyValueObservingOptions . new, context: nil )
7085 webView. addObserver ( self , forKeyPath: #keyPath( WKWebView . estimatedProgress) , options: NSKeyValueObservingOptions . new, context: nil )
7186 }
7287
7388 // Initialize UI
74- // Call after WebView has been initialized
89+ // call after WebView has been initialized
7590 func setupUI( ) {
7691 // UI elements
7792 leftButton. isEnabled = false
@@ -87,7 +102,6 @@ class ViewController: UIViewController {
87102 navigationItem. largeTitleDisplayMode = UINavigationItem . LargeTitleDisplayMode. always
88103 }
89104 if ( useLightStatusBarStyle) {
90- // UIApplication.shared.setStatusBarStyle(.lightContent, animated: true) // iOS < 9
91105 self . navigationController? . navigationBar. barStyle = UIBarStyle . black
92106 }
93107 }
0 commit comments