我可以让我的Mac应用程序阅读桌面的内容,但每当我尝试删除文件时,它表示我没有权限这样做。如果用户有权访问桌面,我是否应该删除文件?
这是我用来删除的代码:
[[NSWorkspace sharedWorkspace] performFileOperation:NSWorkspaceRecycleOperation
source:desktopPath
destination:@""
files:self.filesToDelete
tag:nil];
我也尝试过使用fileManager垃圾桶方法但没有成功。
以下是从fileManager垃圾邮件方法返回的错误:
Error Domain=NSCocoaErrorDomain Code=513 "“file.png” couldn’t be moved to the trash because you don’t have permission to access it." UserInfo=0x60000026a980 {NSURL=file:///Users/me/Desktop/file.png, NSUserStringVariant=(
Trash
), NSUnderlyingError=0x600000257ca0 "The operation couldn’t be completed. (OSStatus error -5000.)"}
实际的垃圾方法调用:
[[NSFileManager defaultManager] trashItemAtURL:url resultingItemURL:nil error:&error];
答案 0 :(得分:2)
除非用户通过打开的对话框选择了文件,或者您使用保存对话框通过应用程序保存了文件,否则您将无法在沙盒应用中将其删除。
有几个目录可以做你想要的,主要是/ tmp和沙箱容器中的目录。