Is there a manner to list all files (documents+data) I have in the iCloud (from a Mac) ? I believe that the NSMetadataQuery object can help me with that, but is there any sample code out there ?
Thanks !
Is there a manner to list all files (documents+data) I have in the iCloud (from a Mac) ? I believe that the NSMetadataQuery object can help me with that, but is there any sample code out there ?
Thanks !
Here some sample code to do a query for txt files in your iCloud folder. If you want to look for other files, simple replace the predicate (NSPredicate *pred = [NSPredicate predicateWithFormat:@"%K ENDSWITH '.txt'", NSMetadataItemFSNameKey];
).
To list all files, you could simply do @"NOT %K.pathExtension = '.'"
but I'm not sure if this is the most elegant method. Suggestions welcome.
Have a look at this post to get the context and full code sample. Here is just the method to look for files.
-(void)loadDocument {
// (2) iCloud query: Looks if there are txt files in the cloud
NSMetadataQuery *query = [[NSMetadataQuery alloc] init];
_query = query;
//SCOPE
[query setSearchScopes:[NSArray arrayWithObject:NSMetadataQueryUbiquitousDocumentsScope]];
//PREDICATE
NSPredicate *pred = [NSPredicate predicateWithFormat:@"%K ENDSWITH '.txt'", NSMetadataItemFSNameKey];
[query setPredicate:pred];
//FINISHED?
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(queryDidFinishGathering:) name:NSMetadataQueryDidFinishGatheringNotification object:query];
[query startQuery];
}