英文:
How to debug wkwebview in iOS 16.4.1 using XCode 14.2?
问题
- 环境:
- MacOS: Monterey 12.6.1
- XCode: 14.2
- iOS: 16.4.1
- 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>
- MacOS: Monterey 12.6.1<br>
- XCode: 14.2<br>
- iOS: 16.4.1<br>
- 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 'inspectable' not found on object of type 'WKWebView *'
}
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(("setInspectable:"))) {
webView.perform(Selector(("setInspectable:")), with: true)
}
After this we can debug the WKWebView in safari.
答案2
得分: 0
考虑在访问可检查属性之前的构建环境,如下所示:
#if __MAC_OS_X_VERSION_MAX_ALLOWED >= 130300 || \
__IPHONE_OS_VERSION_MAX_ALLOWED >= 160400 || \
__TV_OS_VERSION_MAX_ALLOWED >= 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 >= 130300 || \
__IPHONE_OS_VERSION_MAX_ALLOWED >= 160400 || \
__TV_OS_VERSION_MAX_ALLOWED >= 160400
if (@available(macOS 13.3, iOS 16.4, tvOS 16.4, *))
self.wkWebView.inspectable = _webviewDebuggingEnabled;
#endif
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论