john.k.doe
john.k.doe

Reputation: 7563

iCloud Error "The operation couldn't be completed. (LibrarianErrorDoman error 10 - Unable to configure the collection.)"

i want to migrate my existing app to iCloud.

in my attempt to learn what to do, i have tried a sample app that has worked as described in the demo (as seen in lecture 17 of the iTunes stanford university course).

can someone who has had this problem help me diagnose what step i messed up to cause the following to fail? is this just telling me basically that there's no data to query? or is there something else going on that i haven't properly configured?

i am getting the following in my console (which occurs in the code below immediately after i call [self.iCloudQuery startQuery];

item update error: 0, Error Domain=LibrarianErrorDomain Code=10 "The operation couldn’t be completed.
(LibrarianErrorDomain error 10 - Unable to configure the collection.)" UserInfo=0x11ee00 {NSDescription=Unable to
configure the collection.}

i created a development provisioning profile that has iCloud turned on on iTunes connect.

i turned on entitlements. here are the contents:

enter image description here

the code is straight from the Stanford University iTunes lectures:

#import "DocumentViewController.h"

@interface DocumentViewController ()
@property (strong, nonatomic) NSArray* documents; // of NSURLs
@property (strong, nonatomic) NSMetadataQuery* iCloudQuery;
@end

@implementation DocumentViewController
@synthesize documents = _documents;
@synthesize iCloudQuery = _iCloudQuery;

- (void)setDocuments:(NSArray*)documents {
    // always sort documents alphabetically
    documents
      = [documents sortedArrayUsingComparator:^NSComparisonResult(NSURL* url1, NSURL* url2) {
            return [[url1 lastPathComponent] caseInsensitiveCompare:[url2 lastPathComponent]];
        }];
    if (![documents isEqualToArray:_documents])
    {
        _documents = documents;
        [self.tableView reloadData];
    }
}

- (NSMetadataQuery*)iCloudQuery {
    if (!_iCloudQuery)
    {
        _iCloudQuery = [[NSMetadataQuery alloc] init];
        _iCloudQuery.searchScopes
          = [NSArray arrayWithObject:NSMetadataQueryUbiquitousDocumentsScope];
        _iCloudQuery.predicate
          = [NSPredicate predicateWithFormat:@"%K like '*'", NSMetadataItemFSNameKey];
        [[NSNotificationCenter defaultCenter] addObserver:self
                                                 selector:@selector(processCloudQueryResults:)
                                                     name:NSMetadataQueryDidFinishGatheringNotification
                                                   object:_iCloudQuery];
        [[NSNotificationCenter defaultCenter] addObserver:self
                                                 selector:@selector(processCloudQueryResults:)
                                                     name:NSMetadataQueryDidUpdateNotification
                                                   object:_iCloudQuery];
    }
    return _iCloudQuery;
}

#pragma mark - private implementation

- (NSURL*)iCloudURL {
    return [[NSFileManager defaultManager] URLForUbiquityContainerIdentifier:nil];
}

- (NSURL*)iCloudDocumentsURL {
    return [self.iCloudURL URLByAppendingPathComponent:@"Documents"];
}

- (NSURL*)filePackageURLForCloudURL:(NSURL*)url
{
    if ([url.path hasPrefix:self.iCloudDocumentsURL.path])
    {
        NSArray* iCloudDocumentsURLComponents = self.iCloudDocumentsURL.pathComponents;
        NSArray* urlComponents = url.pathComponents;
        if (iCloudDocumentsURLComponents.count < urlComponents.count)
        {
            NSRange newRange = NSMakeRange(0, iCloudDocumentsURLComponents.count+1);
            urlComponents = [urlComponents subarrayWithRange:newRange];
            url = [NSURL fileURLWithPathComponents:urlComponents];
        }
    }
    return url;
}

- (void)processCloudQueryResults:(NSNotification*)notification
{
    [self.iCloudQuery disableUpdates];
    NSMutableArray* documents = [NSMutableArray array];
    NSUInteger resultCount = self.iCloudQuery.resultCount;
    for (NSUInteger i = 0; i < resultCount ; ++i)
    {
        NSMetadataItem* item = [self.iCloudQuery resultAtIndex:i];
        NSURL* url = [item valueForAttribute:NSMetadataItemURLKey];
        url = [self filePackageURLForCloudURL:url];
        [documents addObject:url];
    }
    self.documents = documents;
    [self.iCloudQuery enableUpdates];
}

#pragma mark - overrides

- (void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];
    if (![self.iCloudQuery isStarted])
        [self.iCloudQuery startQuery];
    [self.iCloudQuery enableUpdates];
}

- (void)viewWillDisappear:(BOOL)animated {
    [self.iCloudQuery disableUpdates];
    [super viewWillDisappear:animated];
}

Upvotes: 1

Views: 3292

Answers (1)

john.k.doe
john.k.doe

Reputation: 7563

for anyone else running into this … apparently, this is the error that occurs when you haven't enabled iCloud on the device on which you are testing. once i enabled iCloud on the device, the error stopped occurring in my log.

and so now i know what error to check for in order to present the user with a dialog saying "connecting to iCloud won't work until you sign up for iCloud in the system preferences".

Upvotes: 4

Related Questions