我无法让 NSMetadataQueryDidUpdateNotification 工作。坚持了好几天。下面的代码是否有异常。
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_BACKGROUND, 0ul), ^{
NSString* filePattern = [NSString stringWithFormat:@"*.%@", @"*"];
NSMetadataQuery *aQuery = [[NSMetadataQuery alloc] init];
aQuery.predicate = [NSPredicate predicateWithFormat: @"%K LIKE %@", NSMetadataItemFSNameKey, filePattern];
[aQuery setSearchScopes:@[NSMetadataQueryUbiquitousDataScope]];
[aQuery setValueListAttributes:@[NSMetadataUbiquitousItemPercentDownloadedKey, NSURLUbiquitousItemDownloadingStatusKey,NSURLUbiquitousItemIsDownloadingKey,NSURLUbiquitousItemDownloadRequestedKey]];
_query = aQuery;
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(liveUpdate:)
name:NSMetadataQueryDidUpdateNotification
object:aQuery];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(initalGatherComplete:) name:NSMetadataQueryDidFinishGatheringNotification object:aQuery];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(gatherProgress:) name:NSMetadataQueryGatheringProgressNotification object:aQuery];
[aQuery enableUpdates];
dispatch_async(dispatch_get_main_queue(), ^{
[aQuery startQuery];
});
});