gpt4 book ai didi

ios - 无法从 Webviewcontroller 打开 Safari 浏览器

转载 作者:行者123 更新时间:2023-11-30 11:34:35 26 4
gpt4 key购买 nike

我正在 Webviewcontroller 中打开链接。我在 webview Controller 上创建了一个按钮来在 Safari 浏览器中打开该链接。我面临的问题是,当我在 Web View Controller 中完全加载之前打开 url 时,它会在 Safari 浏览器中成功打开。但是当 URL 在 webview Controller 中完全加载时,它不会打开 Safari Broswer。

我的代码是:

let alertController = UIAlertController(title: nil, message: nil, preferredStyle: UIAlertControllerStyle.actionSheet)
alertController.addAction(UIAlertAction(title: NSLocalizedString("Open in Safari", comment: ""), style: .default, handler: { (UIAlertAction) -> Void in
self.openInSafari()
}))

if (UIDevice.current.userInterfaceIdiom == .phone){
alertController.addAction(UIAlertAction(title: NSLocalizedString("Cancel",comment: ""), style: .cancel, handler:nil))
}

以及打开 Safari 浏览器的函数:

func openInSafari(){

if #available(iOS 10.0, *) {
UIApplication.shared.open(URL(string: self.currentUrl)!, options: [:],completionHandler: nil)
} else {
UIApplication.shared.openURL(URL(string: self.currentUrl)!)
}

}

截图:

Screenshot 1 Screenshot 2

最佳答案

请尝试一次:

guard let url = URL(string: self.currentUrl) else {
return //be safe
}

if #available(iOS 10.0, *) {
UIApplication.shared.open(url, options: [:], completionHandler: nil)
} else {
UIApplication.shared.openURL(url)
}

关于ios - 无法从 Webviewcontroller 打开 Safari 浏览器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49898349/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com