OSX でディスクをアンマウントしようとしています。コードは正常に動作しますが、エラーが発生した場合にのみ、ディスクが正常にアンマウントされたときにコールバックが呼び出されません。DiskArbitrationProgGuide を読み、手順に従いましたが、まだ進展がありません。誰か助けてくれませんか?
@interface DriverUtilitiesController()
void unmount_done(DADiskRef disk,
DADissenterRef dissenter,
void *context);
@end
+ (void)umnountDrivePath:(NSString *)voulumePath
{
DASessionRef session = DASessionCreate(kCFAllocatorDefault);
CFURLRef path = CFURLCreateWithString(NULL, (__bridge CFStringRef)voulumePath, NULL);
DADiskRef disk = DADiskCreateFromVolumePath(kCFAllocatorDefault, session, path);
DADiskUnmount(disk, kDADiskUnmountOptionDefault, unmount_done, NULL);
CFRelease(disk);
}
#pragma mark - Unmount Callback
void unmount_done(DADiskRef disk,
DADissenterRef dissenter,
void *context)
{
NSLog(@"Inside unmount_done");
if (dissenter)
{
// Unmount failed. //
NSLog(@"Unmount failed.");
} else {
NSLog(@"Unmounted Volume");
}
}
更新中。Ken Thomases のおかげで、コードが動作するようになりました
- (id)init
{
self = [super init];
self.session = DASessionCreate(kCFAllocatorDefault);
DASessionScheduleWithRunLoop(_session, [[NSRunLoop mainRunLoop] getCFRunLoop], kCFRunLoopDefaultMode);
return self;
}
- (void)umnountDrivePath:(NSString *)voulumePath
{
CFURLRef path = CFURLCreateWithString(NULL, (__bridge CFStringRef)voulumePath, NULL);
DADiskRef disk = DADiskCreateFromVolumePath(kCFAllocatorDefault, self.session, path);
DADiskUnmount(disk, kDADiskUnmountOptionDefault, unmount_done, (__bridge void *)(self));
CFRelease(disk);
}
void unmount_done(DADiskRef disk,
DADissenterRef dissenter,
void *context)
{
if (dissenter)
{
// Unmount failed. //
NSLog(@"Unmount failed.");
} else {
NSLog(@"Unmounted Volume");
}
DriverUtilitiesController *driverUtilitiesController = (__bridge DriverUtilitiesController *)context;
[driverUtilitiesController clearUnmountCallback];
}
- (void)clearUnmountCallback
{
DASessionUnscheduleFromRunLoop(_session, [[NSRunLoop mainRunLoop] getCFRunLoop], kCFRunLoopDefaultMode);
CFRelease(self.session);
}