SwiftUI WKWebView disable link interactions
Here is correct delegate callback
func webView(_ webView: WKWebView, decidePolicyFor navigationAction: WKNavigationAction, decisionHandler: @escaping (WKNavigationActionPolicy) -> Void) {
if navigationAction.navigationType == .linkActivated {
decisionHandler(.cancel)
} else {
decisionHandler(.allow)
}
}
depending of used HTML, probably also might be disabled .formSubmitted
, if needed.
Disable link drag on WKWebView
I found the solution here: How to disable iOS 11 and iOS 12 Drag & Drop in WKWebView?
This is my working code:
private func disableDragAndDropInteraction() {
var webScrollView: UIView? = nil
var contentView: UIView? = nil
if #available(iOS 11.0, *) {
guard let noDragWebView = webView else { return }
webScrollView = noDragWebView.subviews.compactMap { $0 as? UIScrollView }.first
contentView = webScrollView?.subviews.first(where: { $0.interactions.count > 1 })
guard let dragInteraction = (contentView?.interactions.compactMap { $0 as? UIDragInteraction }.first) else { return }
contentView?.removeInteraction(dragInteraction)
}
}
override func viewDidAppear(_ animated: Bool) {
disableDragAndDropInteraction()
}
You also have to add disableDragAndDropInteraction()
after initialising WKWebView
, e.g. in viewDidLoad()
.
WKWebView selection haptics when selection is turned off
I'm having the same issue and I found something that seems to work just fine:
let longPress:UILongPressGestureRecognizer = UILongPressGestureRecognizer(target: nil, action: nil)
longPress.minimumPressDuration = 0.2
webView.addGestureRecognizer(longPress)
Taken from Disabling user selection in UIWebView.
Related Topics
How to Include Openssl on an iOS Project in a Way That Works
Custom Uibarbuttonitem with Bg Colour and Text Swift 3
How to Get a Low Res Image, or Thumbnail from the Alassetrepresentation in Swift
-Webkit-Overflow-Scrolling: Touch' Broken for Initially Offscreen Elements in iOS7
iPhone /iOS: Presenting HTML 5 Keyboard for Postal Codes
How to Include Openssl on an iOS Project in a Way That Works
iOS 8 [Uiapplication Sharedapplication].Scheduledlocalnotifications Empty
Applying Different Attributes for Different Portions of an Nsattributedstring
Multiple Async Requests at Once in Objective C
How to Get Path to a Subfolder in Main Bundle
Can't Build an App for Distribution After Joining Existing Enterprise Developer Program
Add Udid in Current Provisioning Profile
How to Set UIactivityviewcontroller Gmail Share Subject Different Than Body
Cannot Pass Immutable Value as Inout Argument: Literals Are Not Mutable, Why
iOS Lazy Var Uibarbuttonitem Target Issue
Xcode Export App, Wildcard Error
Swift Unrecognized Selector Sent to Instance - What Am I Missing
Simulator Vs Physical Device: Navigationlink Broken After One Use