Enable web inspector on a webview in Swift
swift, web-inspector, webview
Solution
if you are trying in WKWebView then you can bring WebInspector using the following code snippet
preferences.setValue(true, forKey:"developerExtrasEnabled")
Here is the complete code if anybody wants to try
As far as I have tried it works in OSX and not in iOS
I have raised a question for this anomaly
Update
WKPreference is not key value coding-compliant for the key developerExtrasEnabled so we can't do this using this approach.
Hence the easiest approach would be
Plug the phone into your mac and inspect it through the Safari Develop menu..Here are the steps to achieve it.
If you're using iOS >= 6 and you have mountain lion (10.8) or Safari >= 6, you can just:
Open the application in the simulator (or your device in XCode >= 4.5.x)
Open Safari (go to Preferences -> Advanced and make sure "Show Develop Menu in Menubar" is on.
From the Menu-bar (of Safari) select Develop -> iPhone Simulator -> [your webview page].
The beauty is it works for UIWebView,WKWebView too..
Reference
Problem
Trying to build an iPad app with a webview, how would you go about adding the web inspector using swift?