How to get NSMetadataQuery to search inside document package?

I am coding a custom document package type that resides on iCloud drive. The doc package will contain lots of miscellaneous files like images and pdfs. Thus, I need NSMetadataQuery to return the download status of all of the files inside a package.


This was working until I checked "Document is distributed as a bundle." in the Document UTI and added an appropriate Export UTI. These settings finally got macOS to show the correct package icon in Finder and have Finder start treating the package like a file instead of a folder.


Here is my code:


[_query setSearchScopes:[NSArray arrayWithObject:path]];
[_query setPredicate:[NSPredicate predicateWithFormat:@"%K LIKE '*'", NSMetadataItemFSNameKey]];


I have also tried this:


NSPredicate *filePredicate = [NSPredicate predicateWithFormat:@"kMDItemContentTypeTree = %@", kUTTypeData];
NSPredicate *bundlePredicate = [NSPredicate predicateWithFormat:@"kMDItemContentTypeTree = %@", kUTTypeBundle];
SPredicate *packagePredicate = [NSPredicate predicateWithFormat:@"kMDItemContentTypeTree = %@", kUTTypePackage]; 
NSPredicate *folderPredicate = [NSPredicate predicateWithFormat:@"kMDItemContentTypeTree = %@", kUTTypeFolder]; 
NSPredicate *searchPredicate = [NSCompoundPredicate orPredicateWithSubpredicates:@[filePredicate, bundlePredicate, packagePredicate, folderPredicate]];


Please help!

Accepted Reply

This is solved here: https://forums.developer.apple.com/thread/88043

Replies

This is solved here: https://forums.developer.apple.com/thread/88043