2

I have WKWebView application, and i want to stop it from parsing phone numbers and links in texts, i set

webView.configuration.dataDetectorTypes = [
     WKDataDetectorTypes.address
];

before actually loading page, but it doesn't help, full code looks like

let url = URL(string: link)
var urlRequest = URLRequest(url: url!);

var UUID = String();
if ASIdentifierManager.shared().isAdvertisingTrackingEnabled {
    UUID = ASIdentifierManager.shared().advertisingIdentifier.uuidString;
}

webView.customUserAgent = String(
    format: "%@/%@ %@ EmbeddedBrowser DeviceUID: %@",
    getAppName(),
    getAppVersion(),
    UIWebView().stringByEvaluatingJavaScript(from: "navigator.userAgent")!,
    UUID
);

webView.configuration.dataDetectorTypes = [
    WKDataDetectorTypes.address
];

webView.navigationDelegate = self;
webView.uiDelegate = self;

webView.stopLoading();
webView.load(urlRequest);
Itsmeromka
  • 3,621
  • 9
  • 46
  • 79

2 Answers2

4

From the docs:

WKWebViewConfiguration is only used when a web view is first initialized. You cannot use this class to change the web view's configuration after it has been created.

You have to do this:

let config = WKWebViewConfiguration()
config.dataDetectorTypes = [.address]
let webView = WKWebView(frame: .zero, configuration: config)

you cannot change the values once it is initialized, which is what you are doing now.

Papershine
  • 4,995
  • 2
  • 24
  • 48
3

There's also a setting in Storyboard if initialising it from there. Use the Attributes inspector and then the Data Detectors group

ullstrm
  • 9,812
  • 7
  • 52
  • 83