【发布时间】:2012-11-10 03:59:52
【问题描述】:
对于我正在编写的 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];
问题是这些选择器实际上都没有被回调,甚至一次都没有,而且我特别需要 NSMetaDataQueryDidUpdateNotification 来跟踪云中文件的上传/下载进度。
奇怪的是,前几天我有这个工作,但不知何故它停止了工作,我盲目地试图弄清楚问题到底是什么。通过订阅 NSMetadataQueryDidStartGatheringNotification,我可以看到它确实开始了,但就像它永远不会结束一样。这很奇怪。
我想知道是否有人对上述代码有什么问题有任何线索?或者我还能在哪里寻找问题。
感谢您的宝贵时间:)
【问题讨论】:
-
你有没有发现这有什么问题?我想要一个答案。
-
很遗憾,没有,我从来没有发现这是什么原因。我在网上的任何其他地方都找不到任何解释:(仍然希望得到答案。
-
您是否要搜索所有文件的列表?您是否尝试过将 filepattern 设为单一文件类型,例如 .txt?
-
我在this apple sample 之后设计了我的查询,我也遇到了同样的问题。在主线程上运行并不能修复它。
标签: objective-c ios icloud nsnotificationcenter nsmetadataquery