iOS11: 手动删除后无法在 iCloud 驱动器中再次创建文件夹

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

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

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

它给出如下错误:

"file.txt" couldn't be moved to "Documents" because either the former doesn't exist, or the folder containing the later doesn't exist.

我只在 iOS11 遇到过这个问题。在 iOS 10 它工作正常。

如何解决这个问题。提前致谢。

我发现如果文件夹被删除需要重新创建,它不会自动创建。所以我会试试这个:

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)") }
}