我想在浏览器中打开一个URL,但出现此错误:
使用未解析的标识符NSWorkspace
我的代码:
if let url = URL(string: "https://www.google.com"), NSWorkspace.shared().open(url) {
print("default browser was successfully opened")
}
您正在尝试为iOS的macOS编码添加代码。为iOS编码时,必须使用UIApplication.shared
if let url = URL(string: "https://google.com"), UIApplication.shared.canOpenURL(url) {
UIApplication.shared.open(url)
}