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:
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
Post a Comment