Reputation: 22901
Trying to build an iPad app with a webview, how would you go about adding the web inspector using swift?
Upvotes: 4
Views: 4422
Reputation: 32270
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
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..
Upvotes: 8
Reputation: 51685
With the device (or the simulator) connected and running your app, launch Safari on your Mac and go to the Develop menu (you'll have to enable it in Safari settings). The device and web view will show up in the menu:
Upvotes: 5