可以使用 UIApplication.shared.open(_:options:completionHandler:)
方法来打开链接。
示例代码:
if let url = URL(string: "https://www.google.com") {
UIApplication.shared.open(url, options: [:]) { success in
if success {
print("The URL was delivered successfully.")
} else {
print("The URL failed to open.")
}
}
}
这将会在系统的默认浏览器中打开链接。