How to disable 3D Touch Link Preview

269 Views Asked by At

Since iOS10 the "3D Touch link preview" has been enabled by default, but how can I disable it in my app? Documentation says it's possible by setting allowsLinkPreview to false, but doing it separately for each use case is too much code. There must be an easier way, right?

I thought this would do it, but I get error "Property does not override any property from its superclass". I hope there's just a small mistake, help would be appreciated:

extension WKWebView {
    override open var allowsLinkPreview: Bool {
        set {
            // no-op
        }
        get {
            return false
        }
    }
}

1

There are 1 best solutions below

1
Vyacheslav Pukhanov On

You could extend WKWebView with a convenience initializer and set the property inside of it. Then use this initializer to instantiate web views.

extension WKWebView {
    convenience init(allowsLinkPreview: Bool) {
        self.init()
        self.allowsLinkPreview = allowsLinkPreview
    }
}

Another option is to make a subclass of WKWebView and add this convenience initializer there.