WKWebView 必须停止检测 phone 个数字

WKWebView must stop detecting phone numbers

我有 WKWebView 应用程序,我想阻止它解析 phone 文本中的数字和链接,我设置

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

在实际加载页面之前,但没有帮助,完整代码看起来像

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);

来自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.

你必须这样做:

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

一旦初始化就无法更改值,这就是您现在所做的。

如果从 Storyboard 那里初始化它,在 Storyboard 中也有一个设置。使用属性检查器,然后使用 Data Detectors