菜鸟教程小白 发表于 2022-12-11 19:01:29

iOS11 : Can't create folder again in iCloud drive once deleted manually


                                            <p><p>我开发了一个应用程序,用于将文件从应用程序保存到 iCloud 驱动器。</p>

<p>我正在将文件从我的应用程序保存到 iCloud 驱动器。所以它按预期工作。它使用 iCloud 驱动器应用程序中保存的文件创建我的应用程序文件夹。
但是,如果我删除该文件夹并尝试从我的应用程序中再次保存该文件,</p>

<p>它给出如下错误:</p>

<blockquote>
<p>&#34;file.txt&#34; couldn&#39;t be moved to &#34;Documents&#34; because either the former doesn&#39;t exist, or the folder containing the later doesn&#39;t exist. </p>
</blockquote>

<p>这个问题我只在 iOS11 中遇到。在 iOS 10 中它可以正常工作。</p>

<p>如何解决此问题。提前致谢。</p></p>
                                    <br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
                                            <p><p>我发现如果文件夹被删除,你需要重新创建它,它不会自动创建它。所以我会试试这个:</p>

<pre><code>let fileManager = FileManager.default
let iCloudPath = FileManager.default.url(forUbiquityContainerIdentifier: nil)?.appendingPathComponent(&#34;DirectoryName&#34;)

do {
    // Try to create the file here
} catch let error {
    // If that operation fails, you print the error and create the folder again
    print(error.localizedDescription)

    do {
      try fileManager.createDirectory(atPath: iCloudPath!.path, withIntermediateDirectories: true, attributes: nil) }
    catch let error {
      print(&#34;Unable to create directory \(error.localizedDescription)&#34;) }
}
</code></pre></p>
                                   
                                                <p style="font-size: 20px;">关于iOS11 : Can&#39;t create folder again in iCloud drive once deleted manually,我们在Stack Overflow上找到一个类似的问题:
                                                        <a href="https://stackoverflow.com/questions/46803420/" rel="noreferrer noopener nofollow" style="color: red;">
                                                                https://stackoverflow.com/questions/46803420/
                                                        </a>
                                                </p>
                                       
页: [1]
查看完整版本: iOS11 : Can&#39;t create folder again in iCloud drive once deleted manually