NSDocumentDirectory used to be in 'Mobile Documents'. Not any more?

So I have been using iCloud in my app, just about from the launch of the iCloud API, many years back.


I'm doing an update of my app now, and I noticed that my iCloud functionality is broken.


Scanning for local documents, gives me a whole bunch of iCloud documents.

Yet, if I want to open one, I find that the file is actually not there, according to NSFileManager.


/private/var/mobile/Library/Mobile%20Documents/APPID~com~steenriver~tlctc/Documents/ is where I used to load these documents from.

But now, the files are no longer there, even though they were found in the NSDocumentDirectory.


Did NSDocumentDirectory change sometime in the past?

Tanks,


Bram


PS: It pains me that I, as an early adopter, now get hit by this.

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

I've been digging through the docs, but it looks like as of iOS8, there is now the concept of a Promised Resource in iOS?

And testing those for existence with NSFileManager will fail, it seems.

How did this ever work pre-iOS8?

Was the break in iOS8 intentional?

NSDocumentDirectory used to be in 'Mobile Documents'. Not any more?
 
 
Q