I'm trying to add my own implementation of 3D touch on links with WKWebView
so I set the allowsLinkPreview
property of my WKWebView
to false
.
But then, impossible to check whether the 3D touch was on a link and impossible to know what link neither.
So I'm wondering if there's a way to set the allowsLinkPreview
property to true
and then to catch the peek event that's triggered when 3D Touching a link?
It is possible. You should set the
allowsLinkPreview
value totrue
and then implement the following methods. Both methods need implemented or else it won't work.In my case, I didn't want to create a previewViewController so I just returned an
SFSafariViewController
and passed in my url. That seemed to work perfectly. As for thecommitPreviewingViewController
method, that is where I put my code to open up a new tab in my browser.Source: iOS 10 Link Preview API in WKWebView