I have succeeded uploading a file to iCloud, which can be seen within icloud space manager(but,what odd is the file name is 'unknown').

I also found a piece of code from apple's document

_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);
}
}

but the result is always 0, no matter NSMetadataQueryUbiquitousDataScope or NSMetadataQueryUbiquitousDocumentsScope.

I also know that icloud has backup function, so does backup has any relation with uploading file by app itself?

有帮助吗?

解决方案

In your predicate try to use "like" instead of "==".

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top