我在icloud驱动器中看不到该文件夹

时间:2019-05-27 19:42:57

标签: swift icloud-drive

我创建了此代码,一切正常,但是在icloud驱动器中看不到该文件夹 该文件已正确创建并已恢复。

活动的icloud

我在info.plist代码上插入

<key>NSUbiquitousContainers</key>
<dict>
    <key>iCloud.$(PRODUCT_BUNDLE_IDENTIFIER)</key>
    <dict>
        <key>NSUbiquitousContainerIsDocumentScopePublic</key>
        <true/>
        <key>NSUbiquitousContainerName</key>
        <string>MyAppName</string>
        <key>NSUbiquitousContainerSupportedFolderLevels</key>
<string>None</string>
    </dict>
</dict>

文件

ViewController类:UIViewController {

@IBOutlet weak var textView: UITextView!

let containerURL =
    FileManager.default.url(forUbiquityContainerIdentifier: nil)
var documentURL: URL?


override func viewDidLoad() {
    super.viewDidLoad()

    //loadFile()
    documentURL = containerURL?.appendingPathComponent(
        "Documents/MyTextFile2.txt")
    if let documentPath = documentURL?.path {
        if (FileManager.default.fileExists(atPath: documentPath,
                                           isDirectory: nil)) {
            if let databuffer = FileManager.default.contents(
                atPath: documentPath) {
                let datastring = NSString(data: databuffer,
                                          encoding: String.Encoding.utf8.rawValue)
                textView.text = datastring as String?
            }
        }
    }
}

@IBAction func salva(_ sender: UIButton) {

    if let url = documentURL {
        do {
            try textView.text.write(to: url, atomically:true,
                                    encoding:String.Encoding.utf8)
            print("File Salvato")
        } catch let error {
            print(error.localizedDescription)
        } }
}// Fine Bottone Salva

}

0 个答案:

没有答案