NSMetaDataQuery从不使用NSMetadataQueryDidFinishGatheringNotification回调 [英] NSMetaDataQuery never calls back with NSMetadataQueryDidFinishGatheringNotification

查看:534
本文介绍了NSMetaDataQuery从不使用NSMetadataQueryDidFinishGatheringNotification回调的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

For an iCloud plugin I'm writing, I subscribe my iCloud manager class to these iCloud NSMetaDataQuery observers:

// 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];

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

The problem is that none of these selectors are actually ever called back, not even once, and I especially need the NSMetaDataQueryDidUpdateNotification to track upload/download progress of files in the cloud.

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

An odd thing is that I had this working the other day, but somehow it just stopped working and I've starred myself blind in trying to figure out what the problem actually is. By subscriping to the NSMetadataQueryDidStartGatheringNotification I can see that it does start, but it's like it never finishes. It is quite weird.

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

I was wondering if anyone have any clue at all as what to be wrong with the above code? Or where else I can look for the problem.

感谢您的时间:)

推荐答案

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

Make sure you start the NSMetadataQuery in the main thread. Back then this requirement was not documented.

这篇关于NSMetaDataQuery从不使用NSMetadataQueryDidFinishGatheringNotification回调的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆