iOS11 : Can't create folder again in iCloud drive once deleted manually
<p><p>我开发了一个应用程序,用于将文件从应用程序保存到 iCloud 驱动器。</p>
<p>我正在将文件从我的应用程序保存到 iCloud 驱动器。所以它按预期工作。它使用 iCloud 驱动器应用程序中保存的文件创建我的应用程序文件夹。
但是,如果我删除该文件夹并尝试从我的应用程序中再次保存该文件,</p>
<p>它给出如下错误:</p>
<blockquote>
<p>"file.txt" couldn't be moved to "Documents" because either the former doesn't exist, or the folder containing the later doesn'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("DirectoryName")
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("Unable to create directory \(error.localizedDescription)") }
}
</code></pre></p>
<p style="font-size: 20px;">关于iOS11 : Can'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]