用WKWebView替换了UIWebView,但是来自Apple的错误仍然相同 [英] Replaced UIWebView with WKWebView, but still same error from Apple

查看:109
本文介绍了用WKWebView替换了UIWebView,但是来自Apple的错误仍然相同的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已从我的应用中删除了UIWebView。但是,当我将iOS应用程序上载到iTunes时,我仍然收到相同的消息 Re:ITMS-90809:API使用率已过时-苹果将停止接受使用UIWebView API的应用程序的提交

I have removed the UIWebView from my app. But when I uploaded the iOS app on iTunes I still got the same message "Re: ITMS-90809: Deprecated API Usage - Apple will stop accepting submissions of apps that use UIWebView APIs"

我在项目中全局搜索了UIWebView,没有搜索结果。这只是意味着UIWebView被删除。
我也已经更新了Pod。

I have searched for UIWebView globally in the project and there are no search results. That simply means UIWebView is removed. I have updated the pods too.

我已使用以下代码验证了应用档案中UIWebView的存在:

I have verified the presence of UIWebView in the app archive using below code:

grep -r "UIWebView" .

响应为

./BCSymbolMaps/F4DBB519-4BC9-3C29-B017-4C0BD603D250.bcsymbolmap:l_OBJC_PROTOCOL_$_UIWebViewDelegate
./BCSymbolMaps/F4DBB519-4BC9-3C29-B017-4C0BD603D250.bcsymbolmap:l_OBJC_LABEL_PROTOCOL_$_UIWebViewDelegate
./BCSymbolMaps/F4DBB519-4BC9-3C29-B017-4C0BD603D250.bcsymbolmap:-[Crashlytics monitorErrorsForUIWebView:]
./BCSymbolMaps/F4DBB519-4BC9-3C29-B017-4C0BD603D250.bcsymbolmap:CLSWebViewIsUIWebViewAlreadyMonitored
./BCSymbolMaps/63FADF77-FD8F-31A1-9B4E-2799F044786E.bcsymbolmap:l_OBJC_PROTOCOL_$_UIWebViewDelegate
./BCSymbolMaps/63FADF77-FD8F-31A1-9B4E-2799F044786E.bcsymbolmap:l_OBJC_LABEL_PROTOCOL_$_UIWebViewDelegate
./BCSymbolMaps/63FADF77-FD8F-31A1-9B4E-2799F044786E.bcsymbolmap:-[Crashlytics monitorErrorsForUIWebView:]
./BCSymbolMaps/63FADF77-FD8F-31A1-9B4E-2799F044786E.bcsymbolmap:CLSWebViewIsUIWebViewAlreadyMonitored
Binary file ./dSYMs/Eureka.framework.dSYM/Contents/Resources/DWARF/Eureka matches

如何检查仍然导致UIWebView错误的代码?

How can I check the code that is still causing the error of UIWebView?

推荐答案

如何检查UIWebView是否已从项目中完全删除?

解决方案是:


  1. 打开终端。在终端中打开项目的根文件夹。

  2. 运行命令:grep -r UIWebView。

  3. 此命令将列出所有包含 UIWebView的窗格。没有更新这些Pod或删除这些Pod并再次执行step 2命令。重复直到所有 UIWebView匹配项都被删除。









下面是一些步骤,这些步骤将指导您将现有的UIWebView更新为WKWebView。



Below are some steps that will guide you to update existing UIWebView to WKWebView.

导入 WebKit

Import the "WebKit" class to the Controller.

假设您使用的是名为 webViewMain的UIWebView。然后转到情节提要,只需将UIWebView替换为UIView。确保已向UIView添加与添加到UIWebView相同的约束。从新的UIView绘制@IBOutlet到UIWebView的现有@IBOutlet。
在这里,您需要将@IBOutlet的类从UIWebView更改为UIView,因为您已将UIWebView替换为UIView。

Suppose you are using a UIWebView named "webViewMain". Then go to your storyboard and simply replace the UIWebView with UIView. Make sure that you have added the same constraints to UIView that were added to UIWebView. Draw @IBOutlet from the new UIView to existing @IBOutlet of UIWebView. Here you need to change the class of @IBOutlet from UIWebView to UIView because you have replaced the UIWebView with UIView.

旧代码: @IBOutlet弱变量webViewMain:UIWebView!
新代码: @IBOutlet弱变量webViewMain:UIView!

然后创建一个新变量以创建一个新的WKWebView。
代码: var webView:WKWebView!

Then create a new variable to create a new WKWebView. CODE: var webView : WKWebView!

添加以下代码,您可以在UIWebView:

Add below code where you load request/html in the UIWebView:

// WKWebView
            // init and load request in webview.
            webView = WKWebView(frame: self.webViewMain.frame)
            webView.navigationDelegate = self            
            self.webView.load(request)
            self.webViewMain.addSubview(webView)
            webView.translatesAutoresizingMaskIntoConstraints = false
// Adding constraints from webView(WKWebView) to webViewMain (UIView)
            webView.leadingAnchor.constraint(equalTo: webViewMain.leadingAnchor, constant: 0).isActive = true
            webView.trailingAnchor.constraint(equalTo: webViewMain.trailingAnchor, constant: 0).isActive = true
            webView.topAnchor.constraint(equalTo: webViewMain.topAnchor, constant: 0).isActive = true
            webView.bottomAnchor.constraint(equalTo: webViewMain.bottomAnchor, constant: 0).isActive = true
            // WKWebView

到现在,您已将UIWebView替换为WKWebView。
现在是委托方法。
UIWebView具有委托类:UIWebViewDelegate
WKWebView具有委托类:WKNavigationDelegate

Till now you have replaced UIWebView with WKWebView . Now comes the delegate methods. UIWebView has delegate class: UIWebViewDelegate WKWebView has delegate class: WKNavigationDelegate

用WKNavigationDelegate替换UIWebViewDelegate。

Replace UIWebViewDelegate with WKNavigationDelegate.

现在是UIWebView与WKWebView的委托方法比较:

UIWebView: func webViewDidFinishLoad(_ webView:UIWebView)
WKWebView: func webView(_ webView: WKWebView,didFinish导航:WKNavigation!)

UIWebView: func webViewDidFinishLoad(_ webView: UIWebView) WKWebView: func webView(_ webView: WKWebView, didFinish navigation: WKNavigation!)

UIWebView: func webViewDidStartLoad(_ webView:UIWebView)
WKWebView: func webView(_ webView:WKWebView,didStartProvisionalNavigation导航:WKNavigation!)

UIWebView: func webViewDidStartLoad(_ webView: UIWebView) WKWebView: func webView(_ webView: WKWebView, didStartProvisionalNavigation navigation: WKNavigation!)

UIWebView: func webView(_ webView:UIWebView,shouldStartLoadWith请求:URLRequest,navigationType:UIWebView.NavigationType)->布尔
这里,我们返回true / false来加载/取消导航。
WKWebView: func webView(_ webView:WKWebView,DecisionPolicyFor navigationAction:WKNavigationAction,DecisionHandler:@escaping(WKNavigationActionPolicy)-> Void)
returndecisionHandler(.allow)/ decisionHandler(.cancel)来加载/取消导航。

UIWebView: func webView(_ webView: UIWebView, shouldStartLoadWith request: URLRequest, navigationType: UIWebView.NavigationType) -> Bool Here we return true/false to load/cancel the navigation. WKWebView: func webView(_ webView: WKWebView, decidePolicyFor navigationAction: WKNavigationAction, decisionHandler: @escaping (WKNavigationActionPolicy) -> Void) Here we returndecisionHandler(.allow)/decisionHandler(.cancel) to load/cancel the navigation.

缩放WebView(WKWebView)的方面适合内容。

To Scale aspect fit content of the webView (WKWebView).

var scriptContent = "var meta = document.createElement('meta');"
    scriptContent += "meta.name='viewport';"
    scriptContent += "meta.content='width=device-width';"
    scriptContent += "document.getElementsByTagName('head')[0].appendChild(meta);"
    webView.evaluateJavaScript(scriptContent, completionHandler: nil)

设置webView的高度:

To set the height of the webView:

webView.evaluateJavaScript("document.readyState", completionHandler: { (complete, error) in
if complete != nil {
    self.webView.evaluateJavaScript("document.body.scrollHeight", completionHandler: {     (height, error) in
     self.constraintWebViewProductDescriptionHeight.constant = height as! CGFloat
    })
}
})

这篇关于用WKWebView替换了UIWebView,但是来自Apple的错误仍然相同的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆