【发布时间】:2018-08-25 18:48:51
【问题描述】:
我正在使用 swift 4 开发网络视图。 我正在加载本地 html 文件,这些页面中有一些指向其他网站的链接,但是一旦我点击其中任何一个,我想将它们加载到 safari 或默认浏览器而不是 WebView(浏览器)中。
我的 webView 被称为“浏览器”
这是我的 ViewController.swift 代码:
import UIKit
import WebKit
class ViewController: UIViewController {
@IBOutlet weak var browser: WKWebView!
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
let htmlpath = Bundle.main.path(forResource: "kusrc/index", ofType: "html")
let url = URL(fileURLWithPath: htmlpath!)
let request = URLRequest(url: url)
browser.load(request)
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
}
有人可以帮帮我吗? google 中的大部分结果都不是我需要的...
是否有可能制作一个 if 语句,询问字符串前缀是否为“http:// 或 https://”,然后打开 safari,否则为“浏览器”
【问题讨论】:
标签: ios swift uiwebview webkit