【发布时间】:2018-03-05 12:56:02
【问题描述】:
我已经查看了这个问题的很多答案,但它们现在似乎已经过时了,没有一个解决方案对我有用,只是给出了很多错误。
我刚刚进入 xcode 和应用程序,并将本地 html 文件“index.html”加载到 WKWebView 中。这很好,加载很好,按原样显示,但是我有一些 tel: 页面上的链接不起作用,我点击它们却什么也没有。我正在为我的 html 文件使用 fraework7,并添加了“外部”类,它可以在 safari 等中使用。
更新:使用以下代码,我可以单击一个链接,它会尝试调用,但随后会出现致命错误
import UIKit
import WebKit
class ViewController: UIViewController, WKNavigationDelegate{
@IBOutlet weak var webview: WKWebView!
override func viewDidLoad() {
webview.navigationDelegate = self
super.viewDidLoad()
let htmlpath = Bundle.main.path(forResource: "index", ofType: "html")
let url = URL(fileURLWithPath: htmlpath!)
let request = URLRequest(url: url)
webview.load(request)
webview.scrollView.bounces = false
webview.configuration.dataDetectorTypes = .phoneNumber
// Do any additional setup after loading the view, typically from a nib.
}
func webView(_ webView: WKWebView, decidePolicyFor navigationAction: WKNavigationAction, decisionHandler: @escaping (WKNavigationActionPolicy) -> Swift.Void) {
if navigationAction.request.url?.scheme == "tel" {
UIApplication.shared.openURL(navigationAction.request.url!)
decisionHandler(.cancel)
}
decisionHandler(.allow)
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
}
html 看起来像:
<tr>
<td>Police / Fire / Ambulance</td>
<td>Emergency Services</td>
<td><a href = "tel:999" class = "external">999</a></td>
</tr>
显然是较大表格的一部分,但这是示例。
任何指针都将不胜感激,因为我多年来一直在兜圈子。
【问题讨论】:
-
更新:我已经尝试了以下代码并且它有效...一旦单击链接时出现“线程 1:信号 SIGABRT”错误。