Reputation: 2356
I can't seem to get NSMetadataQuery to work when I disable iCloud. I put in a valid search URL, but it never registers as finished:
//Check for iCloud
NSURL *ubiq = [[NSFileManager defaultManager]
URLForUbiquityContainerIdentifier:nil];
if (ubiq) {
NSLog(@"iCloud access at %@", ubiq);
self.query = [[[NSMetadataQuery alloc] init] autorelease];
[self.query setSearchScopes:[NSArray arrayWithObject:
NSMetadataQueryUbiquitousDataScope]];
_isiCloudEnabled = YES;
} else {
NSLog(@"No iCloud access");
//Get the doc directory
NSString *path = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0];
self.query = [[[NSMetadataQuery alloc] init] autorelease];
[self.query setSearchScopes:[NSArray arrayWithObjects:
[NSURL fileURLWithPath:path],nil]];
_isiCloudEnabled = NO;
}
NSPredicate *pred = [NSPredicate predicateWithFormat:
@"%K like %@", NSMetadataItemFSNameKey, @"*.adoc"];
[self.query setPredicate:pred];
[[NSNotificationCenter defaultCenter]
addObserver:self
selector:@selector(queryDidFinishGathering:)
name:NSMetadataQueryDidFinishGatheringNotification
object:self.query];
[self.query startQuery];
queryDidFinishGathering: never gets called. When iCloud is enabled, it always gets called. Any idea why?
Upvotes: 3
Views: 857
Reputation: 1494
I was facing the same problem but I am using the ARC in project. This is solved by setting the ivar to self.query variable.
@property (nonatomic, strong) NSMetadataQuery *query;
I think for your problem as you are not using the ARC, you may need to do following things:
you need to set the property
@property (nonatomic, retain) NSMetadataQuery *query;
Upvotes: 2
Reputation: 45108
As of iOS5, NSMetadataQuery
's search scope can only be set to ubiquitous things (NSMetadataQueryUbiquitousDocumentsScope
and NSMetadataQueryUbiquitousDataScope
) so using it with iCloud disabled would be unuseful.
As you are probably guessing the reason queryDidFinishGathering
is never called is because of your query scope, local directories are not supported yet (but suspiciously not throwing exceptions or errors :) )
In my opinion NSMetadataQuery class is not fully ported to iOS, in OSX more scopes can be set , more kinds of NSPredicate
can be set, NSSortDescriptors
work, etc.
Upvotes: 0