Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

WKWebKit: No dataDetectorTypes parameter

In UIWebView, it was fairly easy to add UIDataDetectorTypes to a view:

myUIWebView.dataDetectorTypes = UIDataDetectorTypePhoneNumber;

And so on. However, WKWebView does not seem to have a similar property. This reference mentions that it has moved to the WKWebViewConfiguration property at myWebKitView.configuration, but both the official documentation and the headers themselves make no reference to dataDetectorTypes.

I'm currently trying to migrate an app from using UIWebView to WKWebView, and this app currently has user-configurable UIDataDetectorTypes. So, is there any way to implement this using the provided API, or would I have to write my own code to parse the HTML?

like image 853
steve richey Avatar asked Sep 22 '14 15:09

steve richey


2 Answers

Actually WKwebView doesn't have a dataDetectorTypes property. But In iOS 10 WKWebViewConfiguration has.

Try the following code snippet.

WKWebViewConfiguration *theConfiguration = [[WKWebViewConfiguration alloc] init];
theConfiguration.dataDetectorTypes = WKDataDetectorTypeNone;

WKWebView *webView = [[WKWebView alloc] initWithFrame:_someFrame configuration:theConfiguration];

This will work only from iOS10 onwards.

like image 95
arango_86 Avatar answered Oct 07 '22 20:10

arango_86


The cited article has been updated to reflect changes in the API between iOS 8 betas. As of 8.0.1, there is no dataDetectorTypes property on WKWebView, with no other comparable public API.

Until it's added back into the class, you'd have to implement this yourself with NSDataDetector, or resign yourself to using UIWebView.

like image 39
mattt Avatar answered Oct 07 '22 19:10

mattt