检测卷何时安装在 OS X 上 [英] Detect when a volume is mounted on OS X
问题描述
我有一个 OS X 应用程序需要响应正在安装或卸载的卷.
I have an OS X application that needs to respond to a volume being mounted or unmounted.
我已经通过定期检索卷列表并检查更改来解决此问题,但我想知道是否有更好的方法.
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 上的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!