swift - 'Link' is only available in macOS 11.0 or newer
问题描述
I have a text link that opens a web page externally with safari from my macOS app written with SwiftUI.
var body: some View {
Link("Visit Apple", destination: URL(string: "https://www.apple.com")!)
}
This only works if my deployment target is for macOS 11.0 and above but i want it to work for 10.15 which shows these errors:
'Link' is only available in macOS 11.0 or newer
'init(_:destination:)' is only available in macOS 11.0 or newer
Is there an alternative way to open external links for 10.15?
解决方案
You can use open(_:options:completionHandler:)
.
Try the following:
var body: some View {
Button("Visit Apple") {
UIApplication.shared.open(URL(string: "https://www.apple.com")!)
}
}
To open the URL on macOS:
NSWorkspace.shared.open(URL(string: "https://www.apple.com")!)
推荐阅读
- javascript - 导入子组件仅在反应中显示前端
- reactjs - 如何在 github 页面上运行多个 React 应用程序?
- sql-server - 插入多行数据而不循环表数据
- typescript - 如何使用 AWS CDK 获取现有 EC2 实例 ID 并将其存储到数组中
- karate - 有没有办法使用空手道在 excel/.csv 中读取 Sheet1、Sheet2...?
- javascript - 是否可以通过单击只读输入上的数字按钮来跟踪事件?
- ios - 在目标上调用 xxx 时抛出无法识别的发送到实例的选择器
- mysql - 如何在mysql版本(6.0.11-alpha-community)中使用ISNULL函数
- r - 回答:R 基本错误 - 参数暗示不同的行数
- python - WM_Class 被忽略并且正在运行的应用程序的图标不与停靠/最喜欢的应用程序图标结合