2

I'm trying for two weeks set the user agent of my app but no success.

The answer that I found in all places is the below but it doesn't work for me.

If someone know how to do it or give me the right direction or where I'm making the mistake pleas help me.

override func viewDidLoad() {
    super.viewDidLoad()
    webView = WKWebView(frame: view.frame)

    webView.customUserAgent = "Mozilla/5.0 (iPhone; CPU OS 10_1_1 like Mac OS X) AppleWebKit/602.2.14 (KHTML, like Gecko) Mobile/14B100/TansoDL"

    webViewContainer.addSubview(webView)
    webView.navigationDelegate = self
}
rmaddy
  • 314,917
  • 42
  • 532
  • 579
Mr. James
  • 456
  • 1
  • 5
  • 12
  • 2
    http://stackoverflow.com/questions/26994491/set-useragent-in-wkwebview and https://developer.apple.com/reference/webkit/wkwebview/1415017-evaluatejavascript –  Apr 02 '17 at 21:30
  • @Sneak That duplicate is what this OP is already doing. – rmaddy Apr 02 '17 at 21:32
  • 1
    @rmaddy I didn't mark as a duplicate. Just guided him to the answer since he does not tell why it is not working for him, so this actually falls under: "Questions seeking debugging help ("why isn't this code working?") must include the desired behavior, a specific problem or error and the shortest code necessary to reproduce it in the question itself. Questions without a clear problem statement are not useful to other readers. See: How to create a Minimal, Complete, and Verifiable example." But I havn't flagged it yet, hopefully we get some more details. –  Apr 02 '17 at 21:36
  • What actual user agent string are you getting? How are you testing this? Are you sure you aren't resetting this elsewhere? – Paulo Mattos Apr 02 '17 at 21:57
  • 2
    Make a webrequest to `https://httpbin.org/headers` and you'll see what your [user agent string](https://httpbin.org/headers) is – Code Different Apr 02 '17 at 22:05
  • It's not duplicated because the others don't solve my problem, the problem is that the display mode of the pages are always the same(Desktop). I'm using the simulator – Mr. James Apr 03 '17 at 12:50

0 Answers0