With iCloud, I set up a MetaDataQuery like so:
[query setSearchScopes:[NSArray arrayWithObject:NSMetadataQueryUbiquitousDocumentsScope]];
How do I set up the same MetaDataQuery for my normal local Documents Directory?
The following code will give me a static list of files in my directory - but I was looking for a more dynamic way so that I could use NSMetadataQueryDidUpdateNotification
.
Here is my static code to look for files in my documentsDirectory:
NSArray* localDocuments = [[NSFileManager defaultManager] contentsOfDirectoryAtPath:
[self documentsDirectory] error:nil];
NSArray *onlyPQs = [localDocuments filteredArrayUsingPredicate:[NSPredicate predicateWithFormat:@"self ENDSWITH '.pq'"]];
NSLog(@"local file count: %i", [onlyPQs count]);
for (int i=0; i < [onlyPQs count]; i++) {
NSLog(@"LOCAL:%@", [onlyPQs objectAtIndex:i]);
}
I've been looking for an answer to this question and, according to the documentation (Searching iCloud and the Desktop), it's not possible:
Unlike the desktop, the iOS application’s sandbox is not searchable using the metadata classes. In order to search your application’s sandbox, you will need to traverse the files within the sandbox file system recursively using the NSFileManager class.
On Mac OS X three additional scopes are defined: NSMetadataQueryUserHomeScope
, NSMetadataQueryLocalComputerScope
and NSMetadataQueryNetworkScope
which can be used to achieve this.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With