3

I'm trying to access some files stored in the application's documents directory by using an NSMetadataQuery but the NSMetadataQueryDidFinishGatheringNotification doesn't notify my application. I found this question but the answer was to make the NSMetadataQuery an ivar, which I have already done.

Here's the code I am using:

self.query = [[NSMetadataQuery alloc] init];
[self.query setSearchScopes:[NSArray arrayWithObject:documentsDirectoryURL]];
NSPredicate *pred = [NSPredicate predicateWithFormat:@"%K ENDSWITH '_task'", NSMetadataItemFSNameKey];
[self.query setPredicate:pred];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(queryDidFinishGathering:) name:NSMetadataQueryDidFinishGatheringNotification object:self.query];

[self.query enableUpdates];

[self.query startQuery];

Thanks for your help!

Community
  • 1
  • 1
Carl Goldsmith
  • 750
  • 1
  • 5
  • 11

1 Answers1

6

This is from the Apple document, "About File Metadata Queries" :

iOS allows metadata searches within iCloud to find files corresponding files. It provides only the Objective-C interface to file metadata query, NSMetadataQuery and NSMetadataItem, as well as only supporting the search scope that searches iCloud.

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. Once matching file or files is found, you can access that file in the manner that you require. You are also able to use the NSMedatataItem class to retrieve metadata for that particular file.

So, you have to use NSFileManager instead.

rdelmar
  • 103,982
  • 12
  • 207
  • 218