OGeek|极客世界-中国程序员成长平台

标题: iOS11 : Can't create folder again in iCloud drive once deleted manually [打印本页]

作者: 菜鸟教程小白    时间: 2022-12-11 19:01
标题: 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 中它可以正常工作。

如何解决此问题。提前致谢。



Best Answer-推荐答案


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

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

关于iOS11 : Can't create folder again in iCloud drive once deleted manually,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46803420/






欢迎光临 OGeek|极客世界-中国程序员成长平台 (http://ogeek.cn/) Powered by Discuz! X3.4