删除iCloud Drive中用户选择的文件夹中的文件 [英] Trash files inside user-selected folder inside iCloud Drive
问题描述
我的应用程序可以在任何用户选择的文件夹中使用用户txt文件(创建,更改,删除).我只是在内部存储书签,以访问该用户选择的文件夹和文件.
My app works with user txt-files (create, change, delete) inside any user-selected folder. I just internally store the bookmark to get access to that user-selected folder and files.
现在,在源文件夹位于iCloud Drive内的情况下,使用macOS Catalina时,系统仍然允许我创建和编辑文件.但是不允许丢弃其中一个.当我尝试通过 [[NSFileManager defaultManager] trashItemAtURL:...]
进行操作时,出现以下错误:
Now, with macOS Catalina when the source folder is inside iCloud Drive, system still allows me to create and edit files. But doesn't allow to trash one. When I try to do it via [[NSFileManager defaultManager] trashItemAtURL: ... ]
I get the following error:
Error Domain=NSCocoaErrorDomain
Code=3328
"<filename> couldn’t be moved to the trash
because the volume "<APFS volume name>"
doesn’t have one."
UserInfo={
NSURL=file:///... <filepath>.txt,
NSUserStringVariant=Trash
}
注意:这仅在应用被沙盒化时发生.
有任何想法如何正确清除文件?
P.S.我知道有一个 NSWorkspace recycle ...
方法,但是它会产生一个额外的删除提示,不适合我.
P.S. I know there is a NSWorkspace recycle...
method, but it makes an extra deletion prompt that is not suitable for me.
P.P.S.我仍然可以使用 [[NSFileManager defaultManager] removeItemAtURL:...]
方法,但是我需要目标文件是可恢复的,以防用户改变主意.
P.P.S. I am still able to use [[NSFileManager defaultManager] removeItemAtURL: ...]
method, but I need the target file to be restorable in case user changes his mind.
推荐答案
好.看起来这是一种罕见的情况.但是,如果您遇到同样的情况,这就是我最后得到的结果:
Ok. Looks like it's a rare case. But if you've got into the same situation, here is what I've ended up with:
有一个不推荐使用的功能- FSMoveObjectToTrashSync
-仍然可以正常使用.它现在救了我的屁股.
There is a deprecated function - FSMoveObjectToTrashSync
- that still works just fine. It saved my ass for now.
这篇关于删除iCloud Drive中用户选择的文件夹中的文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!