문제

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?

도움이 되었습니까?

해결책

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

다른 팁

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.

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.

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]];
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top