unresolve nsworkspace swift 3 - 打开网址

时间:2017-04-01 13:58:11

标签: ios swift xcode swift3

我想在浏览器中打开一个网址,但是我收到了这个错误:

使用未解析的标识符NSWorkspace

我的代码:

if let url = URL(string: "https://www.google.com"), NSWorkspace.shared().open(url) {
    print("default browser was successfully opened")
}

1 个答案:

答案 0 :(得分:2)

您正在尝试为iOS的macOS编码添加代码。在为iOS编码时,您必须使用UIApplication.shared

if let url = URL(string: "https://google.com"), UIApplication.shared.canOpenURL(url) { 
    UIApplication.shared.open(url) 
}