2

I have an App in the AppStore since 2013 and it always worked flawlessly. It creates and syncs files on iCloud.

Since iOS14 startDownloadingUbiquitousItemAtURL only downloads a fraction of the existing files. If I start the App in the simulator and iOS14 (and of course on the real devices as well). If I start the App in a simulator using iOS12 or 13 it works as expected.

I don't find anything on the web regarding possible changes in the startDownloadingUbiquitousItemAtURL method.

Here's the code in question:

...
BOOL tt =  [[NSFileManager defaultManager] startDownloadingUbiquitousItemAtURL:cloudFileUrl error:&error] ;

if (error != nil)
{
    NSLog(@"ERROR Loading %@", cloudFileUrl) ;
}
...

tt is true and error is nil, so it seems the sync process has started correctly

However, If I try to access the files with

NSArray *dirContent = [[NSFileManager defaultManager] contentsOfDirectoryAtURL:cloudFileUrl includingPropertiesForKeys:[[NSArray alloc] initWithObjects:NSURLNameKey, nil] options:NSDirectoryEnumerationSkipsHiddenFiles error:&error];

The the array dirContent contains only 3 or 4 elements, even though the folder contains 10 files.

Any idea what the problem could be? I have opened a bug with Apple as well.

matt
  • 515,959
  • 87
  • 875
  • 1,141
  • What is the value for `NSMetadataUbiquitousItemDownloadingStatusKey`? – sbooth Sep 27 '20 at 13:24
  • Can you elaborate a bit more please? Do you have an example how to use this? – user1694772 Sep 28 '20 at 15:32
  • `NSMetadataItem *item = [[NSMetadataItem alloc] initWithURL:cloudFileURL]; id attr = [item valueForAttribute:NSMetadataUbiquitousItemDownloadingStatusKey];` and then compare `attr` to `NSMetadataUbiquitousItemDownloadingStatusCurrent` or one of the other possible download status values. – sbooth Sep 28 '20 at 16:48
  • Hmmm, this does not compile. I am getting a "initWithURL: is not available on iOS" message from Xcode (12.0.1) - this is weird because the documentation clearly states that this method exists. I have the feeling Apple has broken this with iOS14 :-( – user1694772 Oct 01 '20 at 07:21

1 Answers1

0

Ok, the solution ist that this call does not read some files when they are binary. Alleged text files were found.

NSArray *dirContent = [[NSFileManager defaultManager] contentsOfDirectoryAtURL:cloudFileUrl includingPropertiesForKeys:[[NSArray alloc] initWithObjects:NSURLNameKey, nil] options:NSDirectoryEnumerationSkipsHiddenFiles error:&error];

I've replaced the call with this

NSArray *dirContent = [[NSFileManager defaultManager] contentsOfDirectoryAtURL:cloudFileUrl includingPropertiesForKeys:[[NSArray alloc] initWithObjects:NSURLNameKey, nil] options:0 error:&error];

and now it works again.