別の方法。
kIOMediaClass で一致する辞書を作成する
matchingDict = IOServiceMatching(kIOMediaClass);
リムーバブル ストレージ ボリュームのみを取得する場合は、kIOMediaRemovableKey と kCFBooleanTrue でディクショナリを設定します
CFDictionarySetValue(matchingDict, CFSTR(kIOMediaRemovableKey), kCFBooleanTrue);
今ならマッチングサービスも受けられるし、
IOServiceGetMatchingService(kIOMasterPortDefault, matchingDict, &iterator);
これでデバイスを列挙できます。
while((removableMedia = IOteratorNext(iterator)))
{
IORegistryEntryGetName(removableMedia, deviceName);
// and something else you can do
kr = IORegistryGetPath(removableMedia, kIOServicePlane, devicePath);
// compare the path with path you get in device.
// if one device's path is the substring of this media
// we could simply think this media is belong to the device
// you could get mount point by following code
DASessionRef sessionRef = DASessionCreate(kCFAllocatorDefault);
if (sessionRef) {
DADiskRef diskRef - DADiskCreateFromIOMedia(kCFAllocatorDefault, sessionRef, removableMedia);
if (diskRef) {
CFDictionaryRef *diskProperty=DADisCopyDescription(diskRef);
if (property) {
NSURL *mountURL = [(NSDictionary*)property objectForKey:(NSString*)kDADiskDescriptionVolumePathKey];
// mountURL or [mountURL path] is the mount point you want
CFRelease(diskProperty);
}
CFRelease(diskRef);
}
CFRelease(sessionRef);
}
// don't forget to release
IOObjectRelease(removableMedia);
}
そして、以下のようなオブザーバーのマウント/アンマウントイベントを実行できます
[[[NSWorkSpace sharedWorkspace] notificationCenter] addObsever:self selector:@selector(volumeMounted:) name:NSWorkspaceDidMountNotification object:nil];
[[[NSWorkSpace sharedWorkspace] notificationCenter] addObsever:self selector:@selector(volumeUnmounted:) name:NSWorkspaceDidUnmountNotification object:nil];