3

有没有办法检测位于 iCloudDrive 上的文件是否已移动到 iCloudDrive 垃圾箱?我可以检查 URL 以包含“.Trash”,但我正在寻找一种官方方法来检索它。

4

2 回答 2

4

To detect if a file/folder is in Trash use following code:

NSURLRelationship relationship;
NSError *error;
[[NSFileManager defaultManager] getRelationship:&relationship ofDirectory:NSTrashDirectory inDomain:0 toItemAtURL:URL error:&error];
if (relationship == NSURLRelationshipContains) {
    //file is in trash
}
于 2017-11-20T15:45:25.737 回答
2

找到了一个不错的方法来检测这一点。从 iOS11 开始,以下方法是可能的:

NSURL* fileURL; // any file URL pointing to a file resource
NSURL* trashURL = [NSFileManager.defaultManager URLForDirectory:NSTrashDirectory inDomain:NSUserDomainMask appropriateForURL: fileURL create:NO error:NULL];
if (trashURL && [fileURL.path hasPrefix:trashURL.path])
{
    // fileURL is located in the iCloudDrive trash
}
于 2017-10-12T15:24:46.080 回答