2

Im trying to disable the long press on webKit to not let the user Save or Copy in Swift 4.

This is the code im using:

webView.stringByEvaluatingJavaScript(from: "document.body.style.webkitTouchCallout='none';")

I have seen some other answer in objective-c

[webView stringByEvaluatingJavaScriptFromString:@"document.body.style.webkitTouchCallout='none';"];

but converting it to swift it doesn't work.

Thanks in advance for any pointers.

Ashley Mills
  • 50,474
  • 16
  • 129
  • 160
Bilonik
  • 21
  • 4
  • _" it doesn't work."_… what happens? Doesn't compile? Error? Wrong result? – Ashley Mills Oct 24 '18 at 21:31
  • It compiles good, Open the page but its still let me Long touch an image and try to save it or copy. – Bilonik Oct 24 '18 at 21:32
  • Possible duplicate of [Disabling user selection in UIWebView](https://stackoverflow.com/questions/5995210/disabling-user-selection-in-uiwebview) – JAB Oct 24 '18 at 21:33
  • @Bilonik welcome to SO...the above answer lists a number of possible solutions that may work, including intercepting the long press with your own long press gesture. Take a look and see if something works! – JAB Oct 24 '18 at 21:34
  • Thanks, BJHStudios but i have try all those solutions. Im running IOS 12 with Xcode 10 and its still letting me Long press and copy, share , open.... – Bilonik Oct 24 '18 at 21:48
  • By adding `UILongPressGestureRecognizer ` to `webView`, it shouldn't allow copy/share etc. Did you try that? – Kamran Oct 25 '18 at 05:20
  • @Kamran had try let longPress:UILongPressGestureRecognizer = UILongPressGestureRecognizer(target: nil, action: nil) longPress.minimumPressDuration = 0.2 self.webview.addGestureRecognizer(longPress) Still cant disable the save – Bilonik Oct 28 '18 at 17:32

1 Answers1

1

There is a property called allowsLinkPreview with that you can enable or disable the long touch previews.

 webView.allowsLinkPreview = false
Md Imran Choudhury
  • 9,343
  • 4
  • 62
  • 60