Is FSGetVolumeInfo the recommended alternative to NSWorkspace's deprecated mountedLocalVolumePaths method?

岁酱吖の 提交于 2020-02-22 05:10:25

问题


I need to get a list of mounted local volumes on Mac OS X. Previously, the Cocoa class NSWorkspace had a mountedLocalVolumePaths method for getting the array of mount points for such volumes. Since Lion, this is now deprecated, with no hint in the documentation about what we should use instead.

The only other Apple-specific API I have found which provides this information is the FSGetVolumeInfo function from the CoreServices.framework. This enumerates the mounted volumes if you pass kFSInvalidVolumeRefNum for the volume parameter and 1..N for the volumeIndex. It returns the volume name (as a HFSUniStr255) via the volumeName output parameter and the mount point via the rootDirectory output parameter as a FSRef, which in turn can be converted to a URL using CFURLCreateFromFSRef().

This seems a little convoluted and unnecessarily low-level.

There are also the BSD-level functions, getfsstat() and getmntinfo() which both emit an array of statfs structs. The API seems saner than the Core Services version.

Are there any higher-level replacements I should be using instead?


回答1:


There is a much simpler replacement, in a much more logical place than the older methods: NSFileManager's mountedVolumeURLsIncludingResourceValuesForKeys:options: method.



来源:https://stackoverflow.com/questions/10852056/is-fsgetvolumeinfo-the-recommended-alternative-to-nsworkspaces-deprecated-mount

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!