{"title":"Remote Debugging UIWebView","html_url":"https://deallocatedobjects.com/posts/remote-debugging-uiwebview","source_url":"http://hiediutley.com/2011/11/22/debugging-ios-apps-using-safari-web-inspector/","markdown_content":"[Hiedi Utley](https://twitter.com/#!/hiediutley/) has completely brought the awesome with a way to use desktop Safari's WebKit inspector to debug iOS `UIWebView` objects:\r\n\r\n> Wow! What a day! While researching debugging techniques for an upcoming training class I am teaching on PhoneGap, I stumbled over a couple of blogs about a private API in iOS5 that will allow you to debug your UIWebViews right inside desktop Safari using the Web Inspector!\r\n\r\nEnabling the trick requires part of a private API in iOS 5, so don't ship it. It does seem to work great though, and it's pretty simple:\r\n\r\n``` objc\r\n- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {\r\n    // Uncomment to enable remote debugging\r\n    [NSClassFromString(@\"WebView\") _enableRemoteInspector];\r\n\r\n    return YES;\r\n}\r\n```\r\n\r\nThen open up desktop Safari and head over to [http://localhost:9999](http://localhost:9999). It requires that you be running iOS 5 and running inside the iOS Simulator, but still, what a HUGE help.\r\n\r\n(via [Mike Rundle](https://twitter.com/flyosity))\r\n\r\n*Update:* Turns out [Nathan de Vries](https://twitter.com/#!/atnan) did a lot of the original research and discovery on this one, here's his original (and in-depth) write up of it: [Enabling Remote Debugging via Private APIs in Mobile Safari](http://atnan.com/blog/2011/11/17/enabling-remote-debugging-via-private-apis-in-mobile-safari/)","html_content":"<p><a href=\"https://twitter.com/#!/hiediutley/\">Hiedi Utley</a> has completely brought the awesome with a way to use desktop Safari’s WebKit inspector to debug iOS <code>UIWebView</code> objects:</p>\n\n<blockquote>\n<p>Wow! What a day! While researching debugging techniques for an upcoming training class I am teaching on PhoneGap, I stumbled over a couple of blogs about a private API in iOS5 that will allow you to debug your UIWebViews right inside desktop Safari using the Web Inspector!</p>\n</blockquote>\n\n<p>Enabling the trick requires part of a private API in iOS 5, so don’t ship it. It does seem to work great though, and it’s pretty simple:</p>\n<figure class=\"code\" data-lang=\"objective-c\"><figcaption><span class=\"lang\">Objective-C</span></figcaption><pre class=\"shiki shiki-themes github-light github-dark\" style=\"--shiki-light:#24292e;--shiki-dark:#e1e4e8;--shiki-light-bg:#fff;--shiki-dark-bg:#24292e\" tabindex=\"0\"><code><span class=\"line\"><span style=\"--shiki-light:#D73A49;--shiki-dark:#F97583\">-</span><span style=\"--shiki-light:#24292E;--shiki-dark:#E1E4E8\"> (</span><span style=\"--shiki-light:#D73A49;--shiki-dark:#F97583\">BOOL</span><span style=\"--shiki-light:#24292E;--shiki-dark:#E1E4E8\">)application:(UIApplication </span><span style=\"--shiki-light:#D73A49;--shiki-dark:#F97583\">*</span><span style=\"--shiki-light:#24292E;--shiki-dark:#E1E4E8\">)application didFinishLaunchingWithOptions:(</span><span style=\"--shiki-light:#005CC5;--shiki-dark:#79B8FF\">NSDictionary</span><span style=\"--shiki-light:#D73A49;--shiki-dark:#F97583\"> *</span><span style=\"--shiki-light:#24292E;--shiki-dark:#E1E4E8\">)launchOptions {</span></span>\n<span class=\"line\"><span style=\"--shiki-light:#6A737D;--shiki-dark:#6A737D\">    // Uncomment to enable remote debugging</span></span>\n<span class=\"line\"><span style=\"--shiki-light:#24292E;--shiki-dark:#E1E4E8\">    [</span><span style=\"--shiki-light:#005CC5;--shiki-dark:#79B8FF\">NSClassFromString</span><span style=\"--shiki-light:#24292E;--shiki-dark:#E1E4E8\">(</span><span style=\"--shiki-light:#032F62;--shiki-dark:#9ECBFF\">@\"WebView\"</span><span style=\"--shiki-light:#24292E;--shiki-dark:#E1E4E8\">) </span><span style=\"--shiki-light:#005CC5;--shiki-dark:#79B8FF\">_enableRemoteInspector</span><span style=\"--shiki-light:#24292E;--shiki-dark:#E1E4E8\">];</span></span>\n<span class=\"line\"></span>\n<span class=\"line\"><span style=\"--shiki-light:#D73A49;--shiki-dark:#F97583\">    return</span><span style=\"--shiki-light:#005CC5;--shiki-dark:#79B8FF\"> YES</span><span style=\"--shiki-light:#24292E;--shiki-dark:#E1E4E8\">;</span></span>\n<span class=\"line\"><span style=\"--shiki-light:#24292E;--shiki-dark:#E1E4E8\">}</span></span></code></pre></figure>\n<p>Then open up desktop Safari and head over to <a href=\"http://localhost:9999\">http://localhost:9999</a>. It requires that you be running iOS 5 and running inside the iOS Simulator, but still, what a HUGE help.</p>\n\n<p>(via <a href=\"https://twitter.com/flyosity\">Mike Rundle</a>)</p>\n\n<p><em>Update:</em> Turns out <a href=\"https://twitter.com/#!/atnan\">Nathan de Vries</a> did a lot of the original research and discovery on this one, here’s his original (and in-depth) write up of it: <a href=\"https://web.archive.org/web/20111129160255/http://atnan.com/blog/2011/11/17/enabling-remote-debugging-via-private-apis-in-mobile-safari/\">Enabling Remote Debugging via Private APIs in Mobile Safari</a></p>","created_at":"2013-11-16T05:10:25.609Z","updated_at":"2013-11-16T05:10:25.609Z"}