HomeiOS DevelopmentThe right way to disable each long-press and faucet context menus for...

The right way to disable each long-press and faucet context menus for tel: hyperlinks in WKWebView on iPad?


I’m engaged on an iOS app that makes use of WKWebView.
A purpose for my app is to forestall any delicate data from leaking out of the app — for instance, if a cellphone quantity seems in an internet web page, the consumer shouldn’t have the ability to export it to Contacts.

I used to be in a position to disable the long-press context menu with the delegate technique:

func webView(_ webView: WKWebView,
         contextMenuConfigurationForElement elementInfo: WKContextMenuElementInfo,
         completionHandler: @escaping @MainActor (UIContextMenuConfiguration?) -> Void) {
    let config = UIContextMenuConfiguration(identifier: nil, previewProvider: nil) { steered -> UIMenu? in
        if let url = elementInfo.linkURL, url.scheme == "tel" {
            // Return an empty menu -> no context menu proven
            return UIMenu(title: "", youngsters: [])
        }
        return UIMenu(title: "", youngsters: steered)
    }
    completionHandler(config)
}

This works: on iPhone and iPad, long-pressing a cellphone quantity not reveals the system context menu.

On iPad, if I faucet a tel: hyperlink as a substitute of long-pressing it, the system nonetheless reveals a menu (with “Add to Contacts”, and many others.).
• Are there really two totally different sorts of menus for tel: hyperlinks in WKWebView (long-press vs faucet)?
• In that case, how can I forestall the “faucet” menu on iPad in the identical approach I suppressed the long-press one?

Here’s a screenshot of a context menu i wish to do away with:

The right way to disable each long-press and faucet context menus for tel: hyperlinks in WKWebView on iPad?

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

- Advertisment -
Google search engine

Most Popular

Recent Comments