我有这样的代码(我尝试从云打开文档):
NSPredicate *pred = [NSPredicate predicateWithFormat:@"%K ENDSWITH '.card'", NSMetadataItemFSNameKey];
NSMetadataQuery *query = [[NSMetadataQuery alloc] init];
[query setSearchScopes:[NSArray arrayWithObject:NSMetadataQueryUbiquitousDocumentsScope]];
[query setPredicate:pred];
[[NSNotificationCenter defaultCenter]
addObserver:self
selector:@selector(queryDidFinishGathering:)
name:NSMetadataQueryDidFinishGatheringNotification
object:query];
[[NSNotificationCenter defaultCenter]
addObserver:self
selector:@selector(queryDidStartGathering:)
name:NSMetadataQueryDidStartGatheringNotification
object:query];
[[NSNotificationCenter defaultCenter]
addObserver:self
selector:@selector(queryDidUpdate:)
name:NSMetadataQueryDidUpdateNotification
object:query];
[query startQuery];
// ===========================
- (void)queryDidFinishGathering:(NSNotification *)notification {
NSMetadataQuery *query = [notification object];
[query disableUpdates];
[query stopQuery];
[[NSNotificationCenter defaultCenter] removeObserver:self
name:NSMetadataQueryDidFinishGatheringNotification
object:query];
for (NSMetadataItem* item in [query results]) {
NSURL *url = [item valueForAttribute:NSMetadataItemURLKey];
BCCardDocument *doc = [[[BCCardDocument alloc] initWithFileURL:url] autorelease];
[doc openWithCompletionHandler:^(BOOL success) {
if (success) {
NSLog(@"%@", doc.card.number);
}
}];
}
}
但是openWithCompletionHandler 完成块的成功参数总是等于 NO。这可能是什么原因?