所以我试图检测 webView 中的链接点击,然后在新的 URL 中显示这个 url,SFSafariViewController
但是我遇到了一些问题。
有人有什么想法吗?
这就是我目前正在做的事情:
import UIKit
import SafariServices
class ViewController: UIViewController {
@IBOutlet weak var webView: UIWebView!
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
let localfilePath = NSBundle.mainBundle().URLForResource("index", withExtension: "html");
let myRequest = NSURLRequest(URL: localfilePath!);
webView.loadRequest(myRequest);
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
func loadInView(webView: UIWebView, shouldStartLoadWithRequest request: NSURLRequest, navigationType: UIWebViewNavigationType) {
if (navigationType == UIWebViewNavigationType.LinkClicked){
let url = request.URL;
let sfViewController = SFSafariViewController(URL:url!, entersReaderIfAvailable: true)
self.presentViewController(sfViewController, animated: true, completion: { () -> Void in
print("May the force be with you!")
})
}
}
}