Question

hi I'm using DiskArbitration.framework to get list of disks

+(NSArray*)arrayOfDisks {
    DASessionRef session = DASessionCreate(kCFAllocatorDefault);
    if (session) {
        DARegisterDiskAppearedCallback(session, NULL, driveGo, NULL);
        DASessionScheduleWithRunLoop(session,
                                     CFRunLoopGetCurrent(), kCFRunLoopDefaultMode);
        CFRelease(session);
    }
    return nil;
}

void driveGo(DADiskRef disk, void *context) {
    NSLog(@"%s", DADiskGetBSDName(disk));
}

it logs up just fine, but how can I return array back? it just loop so I even dont know how to check is it done or not.

Was it helpful?

Solution

You could change your method and store the array in a private variable:

(void*) driveGo(DADiskRef disk, void *context) {
NSLog(@"%s", DADiskGetBSDName(disk));
self->_myArray = DADiskGetBSDName(disk);

}

OTHER TIPS

it just loop so I even dont know how to check is it done or not.

There is no “done”. Your callback will be called for every “disk” that is currently known to DiskArb and every “disk” that appears from then on. There is no separation between the two.

Most applications should work with that, rather than against it. Let DiskArb tell you the moment new “disks” appear, change (DescriptionChanged), are mounted or unmounted (also DescriptionChanged), or disappear. Keep your information up to date as those changes come in, and always have the current state.

Most applications do not need to get a complete and fixed snapshot of the current set of mounted volumes. But if, for some reason, you do, you might try the getmntinfo function instead.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top