Reputation: 163
I am developing an app with a custom subclassed WKWebView, and I am trying to disable the default options when a user selects some text inside the webview, and implement my own options. However, it seems there are 4 options that cannot be removed and will always show: Select To Here, Look Up, Learn..., and Share...
A previous answer claims it's possible by overriding canPerformAction()
or swizzling canPerformAction
on WKContentView, but I've tried both and it hasn't worked. Specifically, there is no UIResponder selectors available for the 4 options, even though they show up when I print a list of all actions coming into canPerformAction
.
Another answer have claimed it might be possible to disable default options if canPerformAction()
returns false from the First Responder
, except WKWebView refuses to become the First Responder by calling becomeFirstResponder
while selecting text, and forcibly doing so by calling resign
on the WKContentView seems to disable interactions with the WebView altogether. Also tried swizzling canPerformAction
on the child WKContentView, but it seems not to make any difference.
I can only assume the default options are being handled further down the chain, but when I break the chain by setting the next UIResponder to nil
, canPerformAction
no longer gets called and no menu shows up anymore.
I'm at a loss here, how can I simply show a customised menu upon text selection?
Testing on
XCode 11.6
iOS 13.6
Upvotes: 1
Views: 280