NSMetaDataQuery永远不会callbackNSMetadataQueryDidFinishGatheringNotification

对于我正在写的iCloud插件,我订阅了我的iCloudpipe理器类到这些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]; 

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

一件奇怪的事情是,我前些天有这个工作,但不知何故,它停止了工作,我已经盲目地试图弄清楚问题实际上是什么。 通过下注NSMetadataQueryDidStartGatheringNotification我可以看到它开始,但它就像它永远不会完成。 这很奇怪。

我想知道是否有人有任何线索,上面的代码是什么错? 或者我可以在哪里find问题。

感谢您的时间 :)

确保你在主线程中启动了NSMetadataQuery。 那时这个要求没有logging。

这是挖掘的秘密。 我不知道你现在是否已经放弃了,但终究还是可以帮忙的。

事实certificate,对于一些(全部)C ++应用程序configuration,有一个消息泵不会自动运行。 在我的应用程序中,在我的[m_query startQuery]调用之后放置了一个像这样的循环之后,我终于开始获得预期的callback:
// make it look syncronous for now while( m_state != finished ) { Check_For_Interruption(); [[NSRunLoop currentRunLoop] runUntilDate:[NSDate dateWithTimeIntervalSinceNow:timeslice]]; //<--**this line is the key** }
其中callback被设置为正确地更新m_statevariables。

我的示例只是阻塞,使用它自己的线程时间片来运行循环(除非被达到超时中断),但是这也可以以asynchronous方式设置。

另一件需要注意的事情是那些在遗留支持方面太过分的人:
这种方法确实导致应用程序开始泄漏OS X 10.9及以上版本的机械端口。 尽pipe如此,还没有看到任何新的问题。