如何在iOS 16.4.1中使用XCode 14.2调试WKWebView?

huangapple go评论109阅读模式
英文:

How to debug wkwebview in iOS 16.4.1 using XCode 14.2?

问题

  • 环境:
  1. MacOS: Monterey 12.6.1
  2. XCode: 14.2
  3. iOS: 16.4.1
  4. Safari: 16.2 (17614.3.7.1.7, 17614)
  • 问题:

我想调试我的 WebView,我打开 Safari,但在我的设备检查器中什么都没有。

然后我搜索信息,发现 WKWebView 更改了默认配置。

创建了一个新的设置 (isInspectable) 关于 WKWebView。

而我使用的 XCode 14.2 没有这个属性。

if (@available(iOS 16.4, *)) {
     self.wkWebView.inspectable = YES; //Property 'inspectable' not found on object of type 'WKWebView *'
}

有没有办法在不升级我的 macOS 和安装 XCode 14.3 的情况下调试 WebView?

英文:
  • Environment:<br>
  1. MacOS: Monterey 12.6.1<br>
  2. XCode: 14.2<br>
  3. iOS: 16.4.1<br>
  4. Safari : 16.2 (17614.3.7.1.7, 17614) <br>
  • Question:<br>

I want to debug my webview, and I open safari and nothing in the my device inspector.<br>
Than I search the information, wkwebview change the default config.<br>
Create new setting (isInspectable) about wkwebview.<br>
And I using the XCode 14.2 don't have this property.<br>

if (@available(iOS 16.4, *)) {
     self.wkWebView.inspectable = YES; //Property &#39;inspectable&#39; not found on object of type &#39;WKWebView *&#39;
}

Have any idea to debug webview without upgrade my macOS and install XCode 14.3?<br>

答案1

得分: 4

I also faced the same issue and this solution works for me.

if webView.responds(to: Selector("setInspectable:")) {
    webView.perform(Selector("setInspectable:"), with: true)
}

After this we can debug the WKWebView in Safari.

英文:

I also faced the same issue and this solution works for me.

if webView.responds(to: Selector((&quot;setInspectable:&quot;))) {
    webView.perform(Selector((&quot;setInspectable:&quot;)), with: true)
}

After this we can debug the WKWebView in safari.

答案2

得分: 0

考虑在访问可检查属性之前的构建环境,如下所示:

#if __MAC_OS_X_VERSION_MAX_ALLOWED &gt;= 130300 || \
    __IPHONE_OS_VERSION_MAX_ALLOWED &gt;= 160400 || \
    __TV_OS_VERSION_MAX_ALLOWED &gt;= 160400
    if (@available(macOS 13.3, iOS 16.4, tvOS 16.4, *))
      self.wkWebView.inspectable = _webviewDebuggingEnabled;
#endif
英文:

Considering the building environment before accessing the inspectable property, as below

#if __MAC_OS_X_VERSION_MAX_ALLOWED &gt;= 130300 || \
    __IPHONE_OS_VERSION_MAX_ALLOWED &gt;= 160400 || \
    __TV_OS_VERSION_MAX_ALLOWED &gt;= 160400
    if (@available(macOS 13.3, iOS 16.4, tvOS 16.4, *))
      self.wkWebView.inspectable = _webviewDebuggingEnabled;
#endif

huangapple
  • 本文由 发表于 2023年5月10日 16:04:19
  • 转载请务必保留本文链接:https://go.coder-hub.com/76216183.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定