Iphone NSMetadataQuery不支持';完成时不发送通知(或未完成)

Iphone NSMetadataQuery不支持';完成时不发送通知(或未完成),iphone,objective-c,ios,Iphone,Objective C,Ios,我试图使用NSMetadataQuery访问存储在应用程序文档目录中的一些文件,但NSMetadataQueryDifinishGatheringNotification不会通知我的应用程序。我发现,但答案是使NSMetadataQuery成为ivar,我已经这样做了 以下是我正在使用的代码: self.query = [[NSMetadataQuery alloc] init]; [self.query setSearchScopes:[NSArray arrayWithObject:docu

我试图使用NSMetadataQuery访问存储在应用程序文档目录中的一些文件,但NSMetadataQueryDifinishGatheringNotification不会通知我的应用程序。我发现,但答案是使NSMetadataQuery成为ivar,我已经这样做了

以下是我正在使用的代码:

self.query = [[NSMetadataQuery alloc] init];
[self.query setSearchScopes:[NSArray arrayWithObject:documentsDirectoryURL]];
NSPredicate *pred = [NSPredicate predicateWithFormat:@"%K ENDSWITH '_task'", NSMetadataItemFSNameKey];
[self.query setPredicate:pred];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(queryDidFinishGathering:) name:NSMetadataQueryDidFinishGatheringNotification object:self.query];

[self.query enableUpdates];

[self.query startQuery];

谢谢你的帮助

这来自苹果的文档“关于文件元数据查询”:

iOS允许在iCloud中进行元数据搜索以查找相应文件。它只提供文件元数据查询、NSMetadataQuery和NSMetadataItem的Objective-C接口,并且只支持搜索iCloud的搜索范围

与桌面不同,iOS应用程序的沙箱不能使用元数据类进行搜索。为了搜索应用程序的沙箱,需要使用NSFileManager类递归遍历沙箱文件系统中的文件。找到匹配的一个或多个文件后,您可以按需要的方式访问该文件。您还可以使用NSMedatataItem类来检索该特定文件的元数据

因此,您必须改用NSFileManager