Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/105.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Html 从UIWebView打开Safari中的特定链接_Html_Ios_Swift_Safari_Uiwebview - Fatal编程技术网

Html 从UIWebView打开Safari中的特定链接

Html 从UIWebView打开Safari中的特定链接,html,ios,swift,safari,uiwebview,Html,Ios,Swift,Safari,Uiwebview,我有一个UIWebView,它加载一个本地index.html文件 但是,我想在Safari中打开此html文件中的外部链接,而不是在UIWebView中打开 从safari中的ui按钮打开链接非常简单: UIApplication.sharedApplication().openURL(NSURL(string: "http://www.stackoverflow.com")) 从外部链接打开Instagram应用程序也很有魅力 <a href="instagram://media?i

我有一个
UIWebView
,它加载一个本地index.html文件

但是,我想在Safari中打开此html文件中的外部链接,而不是在
UIWebView
中打开

从safari中的
ui按钮打开链接非常简单:

UIApplication.sharedApplication().openURL(NSURL(string: "http://www.stackoverflow.com"))
从外部链接打开Instagram应用程序也很有魅力

<a href="instagram://media?id=434784289393782000_15903882">instagram://media?id=434784289393782000_15903882</a>

这是你可以做到的

func webView(webView: UIWebView, shouldStartLoadWithRequest request: NSURLRequest, navigationType: UIWebViewNavigationType) -> Bool {
        if let url = request.URL where navigationType == UIWebViewNavigationType.LinkClicked {
            UIApplication.sharedApplication().openURL(url)
            return false
        }
        return true
    }

嗯,似乎还是有点不对劲。我已经添加了我的swift代码,包括你的函数。你能帮我看看出了什么问题吗?非常感谢!您是否已指定,
UIWebView
delegate?
import UIKit

class AccessoriesViewController: UIViewController, UIWebViewDelegate {


    @IBOutlet weak var webView:UIWebView!

    override func viewDidLoad() {
        super.viewDidLoad()


        if let url = NSBundle.mainBundle().URLForResource("accessories", withExtension: "html") {
            webView.loadRequest(NSURLRequest(URL: url))
        }



    }
    override func preferredStatusBarStyle() -> UIStatusBarStyle {
        return UIStatusBarStyle.LightContent;
    }

    func webView(webView: UIWebView, shouldStartLoadWithRequest request: NSURLRequest, navigationType: UIWebViewNavigationType) -> Bool {
        if let url = request.URL where navigationType == UIWebViewNavigationType.LinkClicked {
            UIApplication.sharedApplication().openURL(url)
            return false
        }
        return true
    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }


}
func webView(webView: UIWebView, shouldStartLoadWithRequest request: NSURLRequest, navigationType: UIWebViewNavigationType) -> Bool {
        if let url = request.URL where navigationType == UIWebViewNavigationType.LinkClicked {
            UIApplication.sharedApplication().openURL(url)
            return false
        }
        return true
    }