在任何Finder.app系统上确定macOS的NSURL的正确方法是什么?
这是背景。我的应用程序中有以下代码:
NSWorkspace.shared.openFile(pathToTempFile, withApplication: "Finder")这将导致Swift编译器警告我:
'openFile(_:withApplication:)' was deprecated in macOS 11.0: Use -[NSWorkspace openURLs:withApplicationAtURL:configuration:completionHandler:] instead.切换到较新的API的问题是,我不知道如何确定Finder的withApplicationAtURL参数。显然,我可以在自己的系统上定位到Finder的路径,但我不知道这是否是所有macOS系统的正确路径,更不用说macOS的未来版本了。我只会硬编码对我有用的东西。
我在苹果文档中找不到任何API,也无法在搜索到的网页上找到Finder.app的网址。我能做什么?
发布于 2022-07-20 19:57:50
NSWorkspace.shared.urlForApplication(withBundleIdentifier: "com.apple.Finder")
// $R1: Foundation.URL? = "file:///System/Library/CoreServices/Finder.app/"https://stackoverflow.com/questions/73057423
复制相似问题