title: UIDocument not saving?
body: <p>No matter what I try, this isn't working...</p>
  
  <p>I am trying to use <code>UIDocument</code> to save my (text) files locally. When I create a file (i.e. it isn't loaded), it saves fine. <strong>However</strong>, if I load my file by opening it and then save it, it simply won't save.</p>
  
  <p><strong>EDIT</strong>: I try to save my documents when the app enters the background. However, it seems that the app actually "finishes saving" the documents when I enter the foreground. Is my app not allowed to save documents while in the background?  </p>
  
  <p>I've checked my URLs and they're all valid.</p>
  
  <p>Here is the code for making the document from scratch:</p>
  
  <pre><code>document = [[MyDocumentClass alloc] initWithFileURL:fileURL];
  </code></pre>
  
  <p><code>fileURL</code> was made previously.
  When loading I don't open or create it, I simply save it when the user quits the app.</p>
  
  <p>If the file already exists on disk:</p>
  
  <p>Here is the code for opening:</p>
  
  <pre><code>[document openWithCompletionHandler:^(BOOL success){
      if (!success) {
          NSLog(@"FAILED TO OPEN DOCUMENT");
      }
  
      // Code to handle document's data
  }];
  </code></pre>
  
  <p>And for saving:</p>
  
  <pre><code>[document saveToURL:[NSURL fileURLWithPath:path] forSaveOperation:UIDocumentSaveForOverwriting completionHandler:^(BOOL success){
      if (!success || document.documentState == UIDocumentStateSavingError) {
      NSLog(@"FAILED TO CLOSE DOCUMENT");
      }
  }];
  </code></pre>
  
  <p>My document encodes and provides its data correctly in <code>contentsForType: error:</code>, given that it saves correctly when first being created.</p>
  
  <p>I don't get any errors in <code>handleError: userInteractionPermitted:</code></p>
  
  <p>Any ideas?</p>
  
  <p><strong>N.B.</strong> I save my data in <code>applicationDidEnterBackground:</code></p>
  
  <p>And the completion handler for <code>saveToURL: forSaveOperation: completionHandler:</code> is never called...</p>