问题
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"
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.
I have verified the presence of UIWebView in the app archive using below code:
grep -r "UIWebView" .
The response is
./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
How can I check the code that is still causing the error of UIWebView?
回答1:
How can I check if the UIWebView is completely removed from the project or not?
Solution is:
- Open terminal. Open your project root folder in terminal.
- Run Command: grep -r "UIWebView" .
- This command will list all the pods that contains “UIWebView”. No either update these pods or remove these pods and ren the step 2 command again. Repeat till all “UIWebView” matches are not removed.
Below are some steps that will guide you to update existing UIWebView to WKWebView.
Import the “WebKit
” class to the Controller.
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.
Older Code: @IBOutlet weak var webViewMain: UIWebView!
New Code: @IBOutlet weak var webViewMain: UIView!
Then create a new variable to create a new WKWebView.
CODE: var webView : WKWebView!
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
Till now you have replaced UIWebView with WKWebView . Now comes the delegate methods. UIWebView has delegate class: UIWebViewDelegate WKWebView has delegate class: WKNavigationDelegate
Replace UIWebViewDelegate with WKNavigationDelegate.
Now comes delegate method comparison for UIWebView vs WKWebView:
UIWebView: func webViewDidFinishLoad(_ webView: UIWebView)
WKWebView: func webView(_ webView: WKWebView, didFinish navigation: WKNavigation!)
UIWebView: func webViewDidStartLoad(_ webView: UIWebView)
WKWebView: func webView(_ webView: WKWebView, didStartProvisionalNavigation navigation: WKNavigation!)
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.
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)
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
})
}
})
来源:https://stackoverflow.com/questions/61575655/replaced-uiwebview-with-wkwebview-but-still-same-error-from-apple