在任何 macOS 系統上確定 Finder.app 的 NSURL 的正確方法是什么?
這是背景關系。我的應用程式中有以下代碼行:
NSWorkspace.shared.openFile(pathToTempFile, withApplication: "Finder")
這會導致 Swift 編譯器警告我:
'openFile(_:withApplication:)' was deprecated in macOS 11.0: Use -[NSWorkspace openURLs:withApplicationAtURL:configuration:completionHandler:] instead.
切換到較新 API 的問題是我不知道如何確定withApplicationAtURL
Finder 的引數。顯然,我可以在自己的系統上找到 Finder 的路徑,但我不知道這是否是所有 macOS 系統的正確路徑,更不用說未來版本的 macOS。我只是硬編碼對我有用的東西。
我在 Apple 檔案中或從網路搜索中找不到任何可以為我提供該系統上 Finder.app 的 URL 的 API。我能做些什么?
uj5u.com熱心網友回復:
NSWorkspace.shared.urlForApplication(withBundleIdentifier: "com.apple.Finder")
// $R1: Foundation.URL? = "file:///System/Library/CoreServices/Finder.app/"
轉載請註明出處,本文鏈接:https://www.uj5u.com/qiye/504406.html
標籤:迅速 可可 nsurl 发现者 nsworkspace