xcode - How do I change the WKWebview's user agent in OS X Yosemite? -


How do you change the user agent used by WKWebview ?

The old WebView , I can write the following to change the user agent:

MyWebView Set CustomUserAgent: @ "Macintosh ; Intel Mac OS X 10_9_4) Apple WebKat / 537.77.4 (KHTML, like XBOX) / 7.0.5 Safari / 537.77.4 "]; Swift is very easy to simply navigate your app didFinishLaunchingWithOptions

  NSUserDefaults.standardUserDefaults (). RegisterDefaults (["UserAgent": "Custom Agent"])  

If you want to add an existing agent string:

  UserAgent = UIWebView () . StringByEvaluatingJavaScriptFromString ("navigator.userAgent")! + "Custom Agent" NSUserDefaults.standardUserDefaults (). RegisterDefaults (["UserAgent": userAgent])  

Note: You must uninstall and restore the app to avoid adding an existing agent string.


Comments

Popular posts from this blog

c# - SignalR: "Protocol error: Unknown transport." when navigating to hub -

c# - WPF Expander overlay used in ItemsControl -

android - how to get distance of 2 beacons and make a condtion base on that distance -