挂载磁盘映像时磁盘仲裁的双重回调

发布于 2024-09-03 01:24:16 字数 127 浏览 7 评论 0原文

我在使用 DiskArbitration 框架时遇到问题,为了捕获磁盘映像安装,我注册了 DARegisterDiskMountApprovalCallback。问题是每次挂载磁盘映像时,都会调用回调两次。这是为什么?我该如何解决这个问题?

I have a problem using DiskArbitration framework, to catch disk image mounting I register for DARegisterDiskMountApprovalCallback. The problem is that each time a disk image is mounted, the callback is called twice. Why is that and how can I solve this?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

谁许谁一生繁华 2024-09-10 01:24:16

我最终编写了一些代码来检测第二个安装并忽略它。

I ended up coding something to detect the 2nd mount and ignore it.

长途伴 2024-09-10 01:24:16

挂载磁盘后,您经常会看到整个磁盘的事件,然后是该磁盘上不同分区的事件。你需要区分。

static void got_disk(DADiskRef disk, void *context)
{
    CFDictionaryRef dict = DADiskCopyDescription(disk);
    NSNumber *whole = CFDictionaryGetValue(dict, kDADiskDescriptionMediaWholeKey);
    if (![whole boolValue]) {
        // Handle your event only with the partition, not the "whole" disk
        ...
    }
}

CFShow(dict) 放入事件处理程序中并查看会得到什么是非常方便的。

When a disk is mounted you often see an event for the whole disk and then events for distinct partitions on that disk. You'll need to distinguish.

static void got_disk(DADiskRef disk, void *context)
{
    CFDictionaryRef dict = DADiskCopyDescription(disk);
    NSNumber *whole = CFDictionaryGetValue(dict, kDADiskDescriptionMediaWholeKey);
    if (![whole boolValue]) {
        // Handle your event only with the partition, not the "whole" disk
        ...
    }
}

It's very handy to put a CFShow(dict) in your event handler and see what you get.

春花秋月 2024-09-10 01:24:16

您是否在回调中放置了断点以查看调用时的调用堆栈是什么?它可以为您提供一些有关正在发生的事情的提示。

Did you put a breakpoint in your callback to see what are the call-stack when it is called ? It can gives you some hints on what is going on.

扭转时空 2024-09-10 01:24:16

我用这些来抓住那个。我不确定这些与你正在做的事情有什么区别,但它们有效。

[[[NSWorkspace sharedWorkspace] notificationCenter] addObserver:self selector:@selector(mediaMounted:) name:NSWorkspaceDidMountNotification object:[NSWorkspace sharedWorkspace]];

[[[NSWorkspace sharedWorkspace] notificationCenter] addObserver:self selector:@selector(mediaUnmounted:) name:NSWorkspaceWillUnmountNotification object:[NSWorkspace sharedWorkspace]];

I use these the catch that. I'm not sure of the difference these are to what you're doing but they work.

[[[NSWorkspace sharedWorkspace] notificationCenter] addObserver:self selector:@selector(mediaMounted:) name:NSWorkspaceDidMountNotification object:[NSWorkspace sharedWorkspace]];

[[[NSWorkspace sharedWorkspace] notificationCenter] addObserver:self selector:@selector(mediaUnmounted:) name:NSWorkspaceWillUnmountNotification object:[NSWorkspace sharedWorkspace]];
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文