Created
September 23, 2019 11:11
-
-
Save fjtrujy/577a51b27a0541dd7491d1ac3371f8aa to your computer and use it in GitHub Desktop.
Extension for AppendUserAgent function
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| private enum Constants { | |
| static let userAgentJavascript = "navigator.userAgent" | |
| } | |
| extension WKWebView { | |
| func appendUserAgent(_ valueToAppend: String?) { | |
| guard let valueToAppend = valueToAppend else { return } | |
| let group = DispatchGroup() | |
| let queue = DispatchQueue.main | |
| group.enter() | |
| queue.async(group: group) { | |
| self.evaluateJavaScript(Constants.userAgentJavascript) { (result, _) in | |
| if let result = result as? String { | |
| self.customUserAgent = result + valueToAppend | |
| } | |
| group.leave() | |
| } | |
| } | |
| group.wait() | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment