-startDownloadingUbiquitousItemAtURL:error: and NSURLUbiquitousItemDownloadRequestedKey

I'm trying to update the iCloud data handling in our app, and I'm running into an issue with a particular file on one particular device. This file never downloads & I haven't been able to pinpoint what's off about it.

Right now we just have 2 iCloud accounts & a handful of devices, so I haven't been able to narrow it down yet, but in most cases, all the cloud files download as expected.

However, whether or not the file eventually downloads, the NSURLUbiquitousItemDownloadRequestedKey key seems to be completely useless.

For the following code:

NSError *error = nil;
BOOL success = [[NSFileManager defaultManager] startDownloadingUbiquitousItemAtURL:self.fileURL error:&error];
if (!success) {
	NSLog(@"error downloading %@ : %@", self.fileURL, error);
} else {
	NSDictionary *resourceValues = [self.fileURL resourceValuesForKeys:@[NSURLUbiquitousItemDownloadRequestedKey, NSURLUbiquitousItemIsDownloadingKey, NSURLUbiquitousItemDownloadingErrorKey, NSURLUbiquitousItemDownloadingStatusKey] error:&error];
	if (!error) {
		NSString *downloadStatus = resourceValues[NSURLUbiquitousItemDownloadingStatusKey];
		bool downloadRequested = [resourceValues[NSURLUbiquitousItemDownloadRequestedKey] boolValue];
		NSLog(@"download requested: %d", downloadRequested);
	}
	// ...
}

downloadRequested is always false, regardless of whether or not the cloud file eventually downloads.

I have 2 questions:

  1. is there a way to actually check if a download has been requested for a file?
  2. what could be preventing this file from downloading? -startDownloadingUbiquitousItemAtURL:error: doesn't report an error, NSURLUbiquitousItemDownloadingErrorKey is always nil, and no error is reported in the NSMetadataQuery observer.

(not that the NSMetadataQuery actually works for monitoring the status of the download, I've never managed to get it working. I basically leave it in as bit of wishful thinking.)

Does the issue only happen on the certain file on the certain device, or does it happen in general on any file on any device?

In the former case, I'll be suspecting that the metadata database is in a bad situation, which I can't explain why but is probably not worth spending time because the issue only impacts one device.

In the latter, I'd start with this sample – If you can reproduce the issue with it, please share the steps and I'd be interested in taking a look.

Best,
——
Ziqiao Chen
 Worldwide Developer Relations.

after some further testing & investigation, we've really only encountered this issue on a single file on this device (iPad Pro). The same test data, with the same Apple/iCloud account on an iPhone doesn't have the issue.

Generally, for testing, we've been manually deleting & copying the test data on a linked Mac, but even after deleting everything & then copying over a clean copy, the issue persists. Restarting the device doesn't eliminate the issue, either.

Is there any way to fix this? We've just been working around it for now, but it makes testing with that device unreliable.

I'd try logging out the iCloud account, restarting the device, and then logging back in with the same or a new account to see if that changes anything.

Best,
——
Ziqiao Chen
 Worldwide Developer Relations.

-startDownloadingUbiquitousItemAtURL:error: and NSURLUbiquitousItemDownloadRequestedKey
 
 
Q