我正在使用UIWebView开发应用程序。在Web视图中我有mailto链接,我想在iOS的邮件应用程序中打开此链接。
这是我的整个应用程序代码
override func viewDidLoad() {
//webview.delegate = self;
webview.dataDetectorTypes = UIDataDetectorTypes.all
super.viewDidLoad()
self.webview.delegate = self
let webURL = URL(string: "http://www.collegiodeirettori.net/palio/")
// Do any additional setup after loading the view, typically from a nib.
let urlRequest = URLRequest(url: webURL!)
webview.loadRequest(urlRequest)
webview.scrollView.bounces = false
}
func webView(_ webView: UIWebView, shouldStartLoadWith request: URLRequest, navigationType: UIWebViewNavigationType) -> Bool {
print(request)
let stringaURL = try! String(contentsOf: request.url!, encoding: String.Encoding.ascii)
if navigationType == UIWebViewNavigationType.linkClicked{
if((stringaURL.range(of:"www.collegiodeirettori.net/palio/")) != nil ){
print("ciao")
//print(stringaURL)
}
else{
print(stringaURL)
UIApplication.shared.openURL(request.url!)
//UIApplication.shared.open(URL(string: stringaURL)!)
return false;
}
}
return true;
}
我已经创建了一个func来控制是否必须在safari中打开一个链接,但是对于mailto链接没有效果。 有任何想法吗?谢谢!