Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to monitor local documents directory NSMetaDataQuery

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]);
}
like image 681
n.evermind Avatar asked Nov 17 '11 22:11

n.evermind


1 Answers

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.

like image 53
Struddie Avatar answered Oct 11 '22 19:10

Struddie