Cocoa卸载驱动器但不弹出驱动器 [英] Cocoa Unmounting drive but not ejecting it

查看:221
本文介绍了Cocoa卸载驱动器但不弹出驱动器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您是否知道卸载驱动器而不弹出驱动器。 NSWorkspace 有一些方法来卸载驱动器,但它也弹出它们。

Do you know you to unmount a drive without ejecting it. NSWorkspace has some methods to unmount drives but it also eject them.

有什么想法吗?

推荐答案

我这样做,如下所示,它卸载驱动器,但不弹出。


(实际上我想弹出磁盘,我只能卸载磁盘。:P请分享如何弹出磁盘。)

I am doing it as follows and it un-mounts the drive but doesn't eject it.

(Actually I want to eject the disk, I can only un-mount the disk. :P Please share how to eject a disk.)

DASessionRef session = DASessionCreate(kCFAllocatorDefault);

CFURLRef path = CFURLCreateWithString(NULL, CFSTR("<path_to_your_volume_here>"), NULL);
DADiskRef disk = DADiskCreateFromVolumePath(kCFAllocatorDefault, session, path);

DADiskUnmount(disk, kDADiskUnmountOptionDefault, __unmountCallback, NULL);

这是我仍在使用的代码,正在开发和测试。

我手动创建路径。您可以使用(并共享)更好的方法以通用方式获取卷的路径。也许这个回答有正确的做法的提示。

我的更新,当我的发展完善和完整。

This is the code I am still working on and is under development and testing.
I am creating the "path" manually. You can use (and share) a better method to get the path of volume in a generic way. Perhaps this answer has hints of doing it the right way.

I'll update when my development is refined and complete.

这篇关于Cocoa卸载驱动器但不弹出驱动器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆