Question

I sometimes have a problem with opening UIDocuments which are stored on iCloud. I call the following code at the very beginning of my app after checking if iCloud is available and getting the results of the NSMetaDataQuery. This works in 98% of all cases. It's just sometimes (e.g. sometimes after re-installing the app) that the completionHandler will never be called:

FRNBDocument *doc = [[FRNBDocument alloc] initWithFileURL:fileURL];
[doc openWithCompletionHandler:^(BOOL success) {

    NSLog(@"... doc: openedWithCompletionHandler");

As you can see from the code, I'm initialising a new UIDocument instance (FRNBDocument), so it can't be the case than an old UIDocument is still open and thus this one fails to open.

The only way to get the app working again is to kill it and then go to the settings.app > iCloud > Documents & Data and turn it OFF and then turn it ON again. When I go back to the app, the UIDocs will be loaded without a problem.

I've noticed that other apps (e.g. xTrail by sophiestication) have the same problem and that I can only get them running again after doing the trick described above.

What is going on?

Was it helpful?

Solution

OK, this seems to be an iCloud bug. I've been in touch with Apple and they suggested to file a bug report. And so I did (id 12260670).

What I'll do now is to simply implement a timer. If the UIDocs have not loaded after 20 secs, I'll show an AlertView, telling the user to go to the settings.app > iCloud > Documents & Data and turn it OFF and then turn it ON again.

This is so frustrating. Unbelievable.

OTHER TIPS

I am having a similar problem. The NSMetadataQuery returns a result but the openWithCompletionHandler: very occasionally does not complete and so the app's data would not load. For a time I had a workaround by checking the NSMetadataUbiquitousItemIsDownloadedKey before attempting to load the document. If it wasn't downloaded I called evictUbiquitousItemAtURL and then startDownloadingUbiquitousItemAtURL. I then had to keep polling with an NSMetadataQuery for the NSMetadataUbiquitousItemIsDownloadedKey to be true at which time I could successfully call openWithCompletionHandler. This appeared to solve the problem. However frustratingly this appears to either no longer work in iOS 6 or doesn't work all the time anymore. Please keep us updated if you find a better workaround or get an update on the bug from Apple.

iCloud access requires returning calling of the function

- (NSURL *)URLForUbiquityContainerIdentifier:(NSString *)containerID

which returns

A URL pointing to the specified ubiquity container, or nil if the container could not be located or if iCloud storage is unavailable for the current user or device.

Reference

As the iCloud is not that responsive, I check if I get the URL and then only proceed to further syncing of the data.

NSURL *ubiq = [[NSFileManager defaultManager] URLForUbiquityContainerIdentifier:nil];
if (ubiq) 
{
    NSLog(@"iCloud access at %@", ubiq);
    [self loadDocument];
} 
else 
{
    NSLog(@"No iCloud access");
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top