NSMetaDataQuery从不使用NSMetadataQueryDidFinishGatheringNotification回调

Cod*_*gle 6 objective-c nsnotificationcenter ios icloud nsmetadataquery

对于我正在编写的iCloud插件,我将iCloud管理器类订阅到这些iCloud NSMetaDataQuery观察器:

// Add a predicate for finding the documents
NSString* filePattern = [NSString stringWithFormat:@"*.%@", @"*"];

self.metadataQuery = [[NSMetadataQuery alloc] init];

// Before starting to query, it is required to set the search scope.
arrayWithObject:NSMetadataQueryUbiquitousDocumentsScope]];

// It is also required to set a search predicate.
[self.metadataQuery setPredicate:[NSPredicate predicateWithFormat:@"%K LIKE %@", NSMetadataItemFSNameKey, filePattern]];

// Listen for the second phase live-updating
[[NSNotificationCenter defaultCenter] addObserver:self
                                         selector:@selector(queryDidReceiveNotification:) name:NSMetadataQueryDidUpdateNotification object:nil];

// Listen for the first phase gathering
[[NSNotificationCenter defaultCenter] addObserver:self
                                      selector:@selector(queryIsDoneGathering:) name:NSMetadataQueryDidFinishGatheringNotification
                                           object:nil];

[self.metadataQuery startQuery];
Run Code Online (Sandbox Code Playgroud)

问题是这些选择器实际上都没有被回调,甚至没有一次,我特别需要NSMetaDataQueryDidUpdateNotification来跟踪云中文件的上传/下载进度.

奇怪的是,我前几天有这个工作,但不知怎的,它只是停止了工作,我已经盲目地试图找出问题究竟是什么.通过订阅NSMetadataQueryDidStartGatheringNotification我可以看到它确实启动,但它就像它永远不会完成.这很奇怪.

我想知道是否有人知道上述代码有什么问题?或者我可以在哪里寻找问题.

感谢您的时间 :)

DrM*_*uer 16

确保NSMetadataQuery在主线程中启动.那时候没有记录这个要求.

  • 现在在`startQuery`下记录了这一点 (2认同)