如何在 10.12 Sierra 上打开 Web Inspector?

How to open Web Inspector on 10.12 Sierra?

这适用于 OS X:

WebPreferences *prefs = [webView preferences];
[prefs setDeveloperExtrasEnabled:YES];

WebInspector *inspector = [[WebInspector alloc] initWithWebView:webView];

但在 mac 中崩溃OS:

-[WebInspector initWithWebView:]: unrecognized selector sent to instance 0xb1ab1ab1a

这个 Private API 被扔掉了吗?

取码from here.

他们已将其重命名为:http://trac.webkit.org/changeset/189654

TLDR:

WebInspector *inspector = [WebInspector alloc];

if ([inspector respondsToSelector:@selector(initWithWebView:)])
    [inspector initWithWebView:webView];
else
    [inspector initWithInspectedWebView:webView];

如果以后有变化,请看WebKit source code