[英]how to open an app from Mac from Xcode project (Cocoa App)
Today I have created an Cocoa Application
for the very first time . 今天,我第一次创建了
Cocoa Application
。 I want to create a simple App which will open an APP from my Mac
, if the file not found it will show a Link
in a Label
to download the App. 我想创建一个简单的应用程序,它将从我的
Mac
打开一个应用程序,如果找不到该文件,它将在Label
显示一个Link
以下载该应用程序。 Here is my code below which I am struggling with . 这是我正在努力的下面的代码。
if let fileCheck = NSURL.fileURL(withPath: "/Applications/Mango.app") {
if NSWorkspace.shared().open(fileCheck as URL) {
print("url successfully opened")
}
} else {
self.downloadLink.insertText("Invalid Path")
}
NSURL.fileURL(withPath: "/Applications/Mango.app") giving me Conditional Binding Must be Optional , I don't know how to fix that. NSURL.fileURL(withPath:“ /Applications/Mango.app”)给我提供条件绑定必须是可选的 ,我不知道如何解决。
And I am struggling with how to show a link on my Label either.
Any kind hearted Dev please help. 任何善良的开发人员请帮助。
got the solution by someone , I don't know why he deleted that ! 得到了解决方案的人,我不知道他为什么删除了!
if FileManager().fileExists(atPath: "/Applications/Mango.app") {
NSWorkspace.shared().open(NSURL(fileURLWithPath: "/Applications/Mango.app") as URL)
} else {
downloadLink.isHidden = false
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.