webView:shouldPreviewElement: of WKUIDelegate is not called

863 Views Asked by At

I've implemented a view controller which is displaying a WKWebView. The web view displays certain pages containing links with a tags, e. g.:

<a id="dien10000513721" href="/ge/tr/issue.html" class="dien">Issue</a>

I would like to add a preview to these links by activating 3d-Touch in the web view, but the delegate method webView:shouldPreviewElement: is never called, when I run my app on a iPhone 7 with iOS 11 and doing a force touch on that link.

When I've created my web view and set the necessary properties with

theWebView.navigationDelegate = self;
theWebView.UIDelegate = self;
theWebView.allowsLinkPreview = YES; // Setting this to NO doesn't help
self.webView = theWebView;

The three delegate methods for previewing are implemented as dummies:

- (BOOL)webView:(WKWebView *)inWebView shouldPreviewElement:(WKPreviewElementInfo *)inElementInfo {
    NSLog(@"url = %@", inElementInfo.linkURL);
    return NO;
}

- (UIViewController *)webView:(WKWebView *)inWebView previewingViewControllerForElement:(WKPreviewElementInfo *)inElementInfo defaultActions:(NSArray<id<WKPreviewActionItem>> *)inPreviewActions {
    return nil;
}

- (void)webView:(WKWebView *)webView commitPreviewingViewController:(UIViewController *)previewingViewController {
    NSLog(@"");
}

Do I still have to perform any important configuration steps? What else could prevent the execution of 3D touch events?

0

There are 0 best solutions below