如何在swift中使用fileManager.unmountVolume
我正试图在swift中弹出/卸载usb驱动器 我想我必须使用fileManager.unmountVolume如何在swift中使用fileManager.unmountVolume,swift,macos,nsfilemanager,Swift,Macos,Nsfilemanager,我正试图在swift中弹出/卸载usb驱动器 我想我必须使用fileManager.unmountVolume let urlString = "/Volumes/UNTITLED/".addingPercentEncoding(withAllowedCharacters: .urlUserAllowed) let url = URL(string: urlString!) fileManager.unmountVolume(at: url!, options: FileManager.Unm
let urlString = "/Volumes/UNTITLED/".addingPercentEncoding(withAllowedCharacters: .urlUserAllowed)
let url = URL(string: urlString!)
fileManager.unmountVolume(at: url!, options: FileManager.UnmountOptions.init(), completionHandler: {(_) in})
wen没有插入驱动器我没有得到输出,但是wen插入驱动器我得到
cfurlcopyresourcepropertyWorkey失败,因为它被传递了一个没有方案的URL
urlString
不是URL字符串--它是文件系统路径。使用URL(字符串:)
从中创建URL会导致URL不完整
改为使用创建
文件://
URL。(在将路径传递给此函数之前,不需要对路径进行百分比编码。)谢谢,只是为了澄清此代码是否正确fileManager.unmountVolume(位于:URL(fileURLWithPath:“/Volumes/UNTITLED”),选项:fileManager.UnmountOptions.init(),completionHandler:{(_)in})