如何在iCloud中搜索上传的文件

时间:2011-10-19 07:33:31

标签: iphone ios ios5 icloud

我成功将文件上传到iCloud,可以在icloud空间管理器中看到(但是,文件名有多奇怪'未知')。

我还从apple的文档中找到了一段代码

_query = [[NSMetadataQuery alloc] init];
[_query setSearchScopes:[NSArray arrayWithObjects:NSMetadataQueryUbiquitousDataScope, nil]];
[_query setPredicate:[NSPredicate predicateWithFormat:@"%K == '*.*'", NSMetadataItemFSNameKey]];
NSNotificationCenter* notificationCenter = [NSNotificationCenter defaultCenter];
[notificationCenter addObserver:self selector:@selector(fileListReceived)
                           name:NSMetadataQueryDidFinishGatheringNotification object:nil];
[notificationCenter addObserver:self selector:@selector(fileListReceived)
                           name:NSMetadataQueryDidUpdateNotification object:nil];
[_query startQuery];
//

[super viewDidLoad];

-(void)fileListReceived 
{
NSArray* queryResults = [_query results];
for (NSMetadataItem* result in queryResults) {
    NSString* fileName = [result valueForAttribute:NSMetadataItemFSNameKey];
    NSLog(@"fileName = %@", fileName);
}
}

但结果始终为0,无论是NSMetadataQueryUbiquitousDataScope还是NSM​​etadataQueryUbiquitousDocumentsScope。

我也知道icloud有备份功能,备份与app本身上传文件有什么关系?

1 个答案:

答案 0 :(得分:2)

在你的谓词中尝试使用“like”而不是“==”。