ICloud: How to read user-created directories

I would like to read a list of all the directories created by the user or application in the iCloud Mobile Documents directory (the one found in Lion under ~ / Library / Mobile Documents). Here is an example of what this directory looks like:

iCloud's Mobile Documents

I tried the following code, but the query that I run will not contain any objects representing my folders (using NSPredicate predicateWithFormat:@"%K.pathExtension = ''", NSMetadataItemFSNameKey ). If I run a query for txt files (using @"%K ENDSWITH '.txt'", NSMetadataItemFSNameKey ), I get 5 objects returned for txt files respectively. Thus, txt file search works, but not for directories. After reading the docs , I noticed that Apple suggests using NSFileWrapper (File Packages) instead of directories. Is iCloud unable to process / detect directories created by the user or application?

Here is my code:

 -(void)loadDocument { NSMetadataQuery *query = [[NSMetadataQuery alloc] init]; _query = query; //Search all files in the Documents directories of the application's iCloud container directories: [query setSearchScopes:[NSArray arrayWithObject:NSMetadataQueryUbiquitousDocumentsScope]]; NSPredicate *pred = [NSPredicate predicateWithFormat:@"%K.pathExtension = ''", NSMetadataItemFSNameKey]; [query setPredicate:pred]; [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(queryDidFinishGathering:) name:NSMetadataQueryDidFinishGatheringNotification object:query]; [query startQuery]; } - (void)queryDidFinishGathering:(NSNotification *)notification { NSMetadataQuery *query = [notification object]; [query disableUpdates]; // You should invoke this method before iterating over query results that could change due to live updates. [query stopQuery]; // You would call this function to stop a query that is generating too many results to be useful but still want to access the available results. [self loadData:query]; [[NSNotificationCenter defaultCenter] removeObserver:self name:NSMetadataQueryDidFinishGatheringNotification object:query]; _query = nil; // we're done with it } - (void)loadData:(NSMetadataQuery *)query { NSLog(@"Query count %i", [query resultCount]); for (int i=0; i < [query resultCount]; i++) { NSMetadataItem *item = [query resultAtIndex:i]; NSURL *url = [item valueForAttribute:NSMetadataItemURLKey]; NSLog(@"%i.URL: %@", i, url); } } 
+6
source share
1 answer

I looked at Storage Management in iClouds settings on Mac OS X Lion. When I click on my application, it will only show different txt files (plus conflicting versions) and no directories. Therefore, I must assume that you can only work with wrappers / file packages, but not with directories.

0
source

Source: https://habr.com/ru/post/899964/


All Articles