我有這樣的代碼(我嘗試打開從雲文檔):openWithCompletionHandler完成處理參數始終= NO
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];
// ================= ======== openWithCompletionHandler完成塊的
- (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);
}
}];
}
}
但成功參數始終等於NO。這可能是什麼原因?