0

I've managed to understand how to incorporate UIManagedDocument into a simple test application and it works as expected! However, now I'm adding support to this basic application so it will work if the user does not want to use iCloud.

So when the URLForUbiquityContainerIdentifier: method returns 'nil', I return the URL of the local documents directory using the suggested method

NSString *documentsDirectoryPath = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0];
return [NSURL fileURLWithPath:documentsDirectoryPath];

However, when I try saving a UIManagedDocument to the local URL (such as: file://localhost/var/mobile/Applications/some-long-identifier/Documents/d.dox) I get the following error:

*** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'This NSPersistentStoreCoordinator has no persistent stores.  It cannot perform a save operation.'

Using this save method:

if (![[NSFileManager defaultManager] fileExistsAtPath:self.managedDocument.fileURL.path]) {
    [self.documentDatabase saveToURL:self.managedDocument.fileURL
                    forSaveOperation:UIDocumentSaveForCreating
                   completionHandler:^(BOOL success) {                           
                       if (success) {
                           //                               
                           //   Add default database stuff here.
                           //
                           dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
                               [self.documentDatabase.managedObjectContext performBlock:^{
                                   [Note newNoteInContext:self.managedDocument.managedObjectContext];
                               }];
                           });
                       } else {
                           NSLog(@"Error saving %@", self.managedDocument.fileURL.lastPathComponent);
                       }
                   }];
}
Adam Carter
  • 4,741
  • 5
  • 42
  • 103

1 Answers1

0

It turns out my persistent store options contained the keys used for the ubiquitous store. These shouldn't be in the documents persistent store options.

Adam Carter
  • 4,741
  • 5
  • 42
  • 103