2011-11-17 83 views
4

随着iCloud的,我成立了像这样一个MetaDataQuery:如何监控本地文件目录NSMetaDataQuery

[query setSearchScopes:[NSArray arrayWithObject:NSMetadataQueryUbiquitousDocumentsScope]]; 

如何设置相同的MetaDataQuery我的本地正常文件目录?

下面的代码会给我一个静态的我的目录中的文件列表 - 但我正在寻找一种更加动态的方式,以便我可以使用NSMetadataQueryDidUpdateNotification

这里是我的静态代码查找文件在我documentsDirectory:

NSArray* localDocuments = [[NSFileManager defaultManager] contentsOfDirectoryAtPath: 
          [self documentsDirectory] error:nil]; 

NSArray *onlyPQs = [localDocuments filteredArrayUsingPredicate:[NSPredicate predicateWithFormat:@"self ENDSWITH '.pq'"]]; 

NSLog(@"local file count: %i", [onlyPQs count]); 

for (int i=0; i < [onlyPQs count]; i++) { 
    NSLog(@"LOCAL:%@", [onlyPQs objectAtIndex:i]); 
} 

回答

5

我一直在寻找一个回答这个问题,并根据文档(Searching iCloud and the Desktop),这是不可能的:

与桌面不同,iOS应用程序的沙盒不可搜索 使用元数据类。为了搜索您的应用程序的 沙盒,您需要使用NSFileManager类递归地遍历沙箱文件 系统中的文件。

在Mac OS X三个附加范围被定义:NSMetadataQueryUserHomeScopeNSMetadataQueryLocalComputerScopeNSMetadataQueryNetworkScope其可用于实现这一目标。

+0

不幸的是,在iOS 8中仍然正确。 – idmean