So this is how I look for iCloud documents:
-(NSMetadataQuery*)makeTextDocumentQuery
{
Class cls = NSClassFromString(@"NSMetadataQuery");
_query = cls ? [ [ cls alloc ] init ] : nil;
if ( !_query )
return nil;
// Search the Documents subdirectory only.
[ _query setSearchScopes:[ NSArray arrayWithObject:NSMetadataQueryUbiquitousDocumentsScope ] ];
// Add a predicate for finding the documents.
NSString* filePattern = [ NSString stringWithFormat:@"*.%@", @"cranelevel" ];
[ _query setPredicate:[NSPredicate predicateWithFormat:@"%K LIKE %@",NSMetadataItemFSNameKey, filePattern ] ];
return _query;
}
-(void)setupAndStartQuery
{
// Create the query object if it does not exist.
if ( !_query )
[ self makeTextDocumentQuery ];
if ( !_query )
return; // if still not there, just give up.
// Register for the metadata query notifications.
NSNotificationCenter* nc = [ NSNotificationCenter defaultCenter ];
[ nc addObserver:self
selector:@selector(processFiles:)
name:NSMetadataQueryDidFinishGatheringNotification
object:nil
];
[ nc addObserver:self
selector:@selector(processFiles:)
name:NSMetadataQueryDidUpdateNotification
object:nil
];
// Start the query and let it run.
[ _query startQuery ];
}
And finaly, I gather the results of the query.
// The query reports all files found, every time.
NSArray* documents = [ _query results ];
//NSFileManager *fm = [ NSFileManager defaultManager ];
for ( NSMetadataItem* item in documents )
{
NSURL* url = [ item valueForAttribute:NSMetadataItemURLKey ];
NSString* name = [ item valueForAttribute:NSMetadataItemDisplayNameKey ];
[ documentURLs setObject:url forKey:name ];
//const BOOL inCloud = [ fm isUbiquitousItemAtURL:url ];
}
NSLog( @"discovered %d documents in the cloud", (int)[ documents count ] );
But if I try to open an url, as reported by the query, I see that this fails:
[ fm fileExistsAtPath:[ url path ] ]
This code used to work.
What is causing the break?
Thanks.
Bram