title: Saving a file to icloud drive
body: <p>I'm trying to save a file to icloud drive. I'm going for the simple version where I don't let the user pick where to save the file, I just save it in the root directory of icloud drive. Here's the code I'm using:</p>
  <pre class="lang-swift prettyprint-override"><code>func exportToFiles() {
      for page in pages {
              let filename = getDocumentsDirectory().appendingPathComponent((page.title ?? &quot;Untitled&quot;) + &quot;.png&quot;)
          if let image = exportImage(page: page, dpi: 300) {
              if let data = image.pngData() {
                  try? data.write(to: filename)
              }
          }
      }
  }
  
  func getDocumentsDirectory() -&gt; URL {
      let driveURL = FileManager.default.url(forUbiquityContainerIdentifier: nil)?.appendingPathComponent(&quot;Documents&quot;)
      return driveURL!
  }
  </code></pre>
  <p>And I have this in my <code>Info.plist</code> file:</p>
  <pre><code>&lt;key&gt;NSUbiquitousContainers&lt;/key&gt;
  &lt;dict&gt;
          &lt;key&gt;iCloud.com.mysite.myapp&lt;/key&gt;
          &lt;dict&gt;
                  &lt;key&gt;NSUbiquitousContainerIsDocumentScopePublic&lt;/key&gt;
                  &lt;true/&gt;
                  &lt;key&gt;NSUbiquitousContainerName&lt;/key&gt;
                  &lt;string&gt;myapp&lt;/string&gt;
                  &lt;key&gt;NSUbiquitousContainerSupportedFolderLevels&lt;/key&gt;
                  &lt;string&gt;Any&lt;/string&gt;
          &lt;/dict&gt;
  &lt;/dict&gt;
  </code></pre>
  <p>In the UI it looks like this works, because there's a slight pause after I tap my button. But when I look in my files, there's nothing there. What am I doing wrong?</p>