问题描述
我有一个OS X应用程序需要响应正在挂载或卸载的卷。
I have an OS X application that needs to respond to a volume being mounted or unmounted.
我已经通过定期检索卷列表并检查更改来解决这个问题,但我想知道是否有更好的方法。 p>
I've already solved this problem by retrieving the list of volumes periodically and checking for changes, but I'd like to know if there is a better way.
推荐答案
注册到您从 [[NSWorkspace sharedWorkspace] notificationCenter]获得的通知中心
然后处理您感兴趣的通知。这些是与卷相关的: NSWorkspaceDidRenameVolumeNotification
, NSWorkspaceDidMountNotification
, NSWorkspaceWillUnmountNotification
和 NSWorkspaceDidUnmountNotification
。
Register to the notification center you get from [[NSWorkspace sharedWorkspace] notificationCenter]
and then process the notifications you are interested in. These are the volume related ones: NSWorkspaceDidRenameVolumeNotification
, NSWorkspaceDidMountNotification
, NSWorkspaceWillUnmountNotification
and NSWorkspaceDidUnmountNotification
.
这篇关于检测OS X上装入卷的时间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!