在 Safari 中快速打开链接 [英] Swift Open Link in Safari
本文介绍了在 Safari 中快速打开链接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我目前正在WebView
中打开我的应用程序中的链接,但我正在寻找在 Safari 中打开链接的选项.
I am currently opening the link in my app in a WebView
, but I'm looking for an option to open the link in Safari instead.
推荐答案
这不是烘焙到 Swift",但您可以使用标准的 UIKit
方法来做到这一点.看看 UIApplication 的 openUrl(_:)
(已弃用) 和 open(_:options:completionHandler:)
.
It's not "baked in to Swift", but you can use standard UIKit
methods to do it. Take a look at UIApplication's openUrl(_:)
(deprecated) and open(_:options:completionHandler:)
.
Swift 4 + Swift 5(iOS 10 及更高版本)
guard let url = URL(string: "https://stackoverflow.com") else { return }
UIApplication.shared.open(url)
Swift 3(iOS 9 及更低版本)
guard let url = URL(string: "https://stackoverflow.com") else { return }
UIApplication.shared.openURL(url)
Swift 2.2
guard let url = URL(string: "https://stackoverflow.com") else { return }
UIApplication.sharedApplication().openURL(url)
这篇关于在 Safari 中快速打开链接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文