top | item 4122502

Debug UIWebView in your iOS app

14 points| dryman | 13 years ago |idryman.org

10 comments

order
[+] brainlock|13 years ago|reply
If you absolutely need to debug something on the device in iOS 5, I wrote this a few weeks ago: https://github.com/brainlock/ios-remote-inspector

I had a rendering bug that only happened on the device, not in the simulator.

This opens the web inspector locally, and exposes a proxy on port 55555 for you to access from your working machine.

Not really useful on iOS 6 anymore :-) but still, useful on iOS 5.

[+] shaggyfrog|13 years ago|reply
Debugging? That's cool. Just don't submit a build with this code in it to Apple -- it will get rejected for using a private API (the underscore in _enableRemoteInspector is a dead giveaway).
[+] sjmulder|13 years ago|reply
This:

    #if (TARGET_IPHONE_SIMULATOR)
takes care of that already, it won’t be in an App Store build.

Another thing to note is that the inspector will use take the first webview in your application. There’s a common trick of creating an off-screen webview for checking the user agent string for whatever reason, and if you use a remote inspector you’ll get that one.

[+] falling|13 years ago|reply
You also don’t want it in the released app so that random guy in the coffee shop cannot connect to your app and mess with it while people use it.
[+] SeoxyS|13 years ago|reply
Uh, shouldn't the class be `UIWebView`, not `NSClassFromString(@"WebView")`? (Specifically, the class name would be missing the UI prefix, and the string-class conversion is redundant.)
[+] dryman|13 years ago|reply
The `_enableRemoteInspector` is a private method to the private class `WebView`. If you use `UIWebView` it will cause runtime exception 'NSInvalidArgumentException', reason: '+[UIWebView _enableRemoteInspector]: unrecognized selector sent to class 0x6df1ec'

If Automatic reference counting (ARC) feature was enabled, the compiler would raise an error for the code `[NSClassFromString(@"WebView") _enableRemoteInspector];` : "No known class method for selector '_enableRemoteInspector.'"