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

python - Strange behavior using PyQt4's 'pyqtSlot' decorator before another decorator -

c# - UnhandledExceptionMode.ThrowException for AppDomain.UnhandledException -

c# - Process.Kill() returns access denied -