How to search for any UIWebView component usage inside a current project?
Hey I tried searching in Xcode.
Couple of the third party libraries used it. (FBSDK for example)
I updated those libraries but that wasn't sufficient.
On the next upload the scary email arrived again.
Then I found this article:
https://medium.com/@zivchen_42755/for-me-that-wasnt-enough-it-didn-t-found-all-of-them-thats-weird-something-to-do-with-pod-i-a068d55b7fab
and in the comments someone mentioned grep
being the medicine.
So I tried grep -r UIWebView /Path/To/Project/*
And it found a couple of the binary frameworks that also use UIWebView. (GoogleSignin, Crashlytics ...)
I updated those too.
On the next upload there was no scary email :D
iOS - UIWebView replaced with WKWebView, but for Apple it’s still there
Try from terminal in your base project folder
grep -r "UIWebView" .
(Be careful to "dot" at the end of line)
This will print out all SDK's (including Pods) which are currently using UIWebView.
Replaced UIWebView with WKWebView, but still same error from Apple
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
})
}
})
Related Topics
How to Overlay One Video on Another in iOS
Custom Font Not Working in Wkwebview Swift
How to Register Undomanager in Swift
Preventing Avcapturevideopreviewlayer from Rotating, But Allow UI Layer to Rotate with Orientation
Cannot Invoke 'Indexof' with an Argument List of Type '(Checklistitem)'
Avplayerviewcontroller Using Audio-Only Avplayer
Bounce Animation on Google Map Marker in iOS? [Objective-C]
Xamarin.iOS Binding Libraries/Native Frameworks
Binding Viewmodel and Textfields with Swiftui
Installing Openssl Library for Xcode
Measuring Time Accurately in Swift for Comparison Across Devices
Xcode 5 - "No Application Records Were Found" When Trying to Validate an Archive
Swift - Add Gesture Recognizer to Object in Table Cell
Obtaining Bluetooth Le Scan Response Data with iOS