是否推荐使用FSGetVolumeInfo替代NSWorkspace不推荐使用的MountedLocalVolumePaths方法? [英] Is FSGetVolumeInfo the recommended alternative to NSWorkspace's deprecated mountedLocalVolumePaths method?
问题描述
我需要获取Mac OS X上已安装的本地卷的列表.以前,可可类NSWorkspace
的 FSGetVolumeInfo
函数(来自CoreServices.framework).如果您为 volume 参数传递kFSInvalidVolumeRefNum
和为 volumeIndex 传递1..N,则将枚举已装入的卷.它通过 volumeName 输出参数返回卷名(作为HFSUniStr255
),并通过 rootDirectory 输出参数返回安装点作为FSRef
,这又可以可以使用CFURLCreateFromFSRef()
转换为URL.
这似乎有点令人费解,而且级别太低了.
还有BSD级别的函数getfsstat()
和getmntinfo()
,它们均发出statfs
结构的数组.该API似乎比Core Services版本更精巧.
我应该使用更高级别的替代品吗?
与旧方法相比,在更合理的位置上有一个更简单的替换方法: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?
There is a much simpler replacement, in a much more logical place than the older methods: NSFileManager's mountedVolumeURLsIncludingResourceValuesForKeys:options:
method.
这篇关于是否推荐使用FSGetVolumeInfo替代NSWorkspace不推荐使用的MountedLocalVolumePaths方法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!