我有一个分区的路径。 如何在不使用终端命令的情况下以编程方式检索该分区的UUID? 一个例子会更有帮助。
I have a path to a partition. How can I retrieve UUID of that partition programatically without using terminal commands? An example will be more helpful.
最满意答案
您可以使用磁盘仲裁框架( Apple参考 )。 Chris Suter在这篇博客中也有一个很好的总结。
您可以使用kDADiskDescriptionMediaUUIDKey获取UUID。 Aaron Burghardt在这个邮件列表线程中描述得很好。 以下是该链接的引用:
获得DADisk后,使用DADiskCopyDescription获取属性字典,您可以在其中找到带有密钥kDADiskDescriptionMediaUUIDKey的UUID(有关其他密钥的信息,请参阅DADisk.h)。 请注意,DADisk是IOMedia对象周围的包装,描述字典直接对应于IOMedia对象中的属性。 此外,CFShow()对于将描述字典打印到控制台很有用。
You can use the Disk Arbitration framework (Apple reference). There is also a good summary at this blog by Chris Suter.
You can get the UUID by using the kDADiskDescriptionMediaUUIDKey. Aaron Burghardt described it well in this mailing list thread. Here is a quote from that link:
Once you have the DADisk, use DADiskCopyDescription to get a dictionary of properties, in which you will find the UUID with the key kDADiskDescriptionMediaUUIDKey (see DADisk.h for other keys that may be of interest). Note, a DADisk is a wrapper around an IOMedia object and the description dictionary corresponds directly to the properties in the IOMedia object. Also, CFShow() is useful for printing the description dictionary to the console.
更多推荐
发布评论