2

A am working with UIDocuments and iCloud. I am successfully able to write out a file to iCloud but not seeing in on the device and the files app.

I have the following in info.plist.

<key>NSUbiquitousContainers</key>
<dict>
    <key>iCloud.myAppName</key>
    <dict>
        <key>NSUbiquitousContainerIsDocumentScopePublic</key>
        <true/>
        <key>NSUbiquitousContainerName</key>
        <string>myAppName</string>
        <key>NSUbiquitousContainerSupportedFolderLevels</key>
        <string>Any</string>
    </dict>
</dict>

Inside my code I can create the directory and then write the file.

   var containerUrl: URL? {
                    return FileManager.default.url(forUbiquityContainerIdentifier: nil)?.appendingPathComponent("myAppName")
                }          
  let url =  containerUrl?.appendingPathComponent("fileName.fileType")           

     print("url: \(url)")

The print returns:

file:///private/var/mobile/Library/Mobile%20Documents/iCloud~myAppName/myAppName/fileName.fileType

I can test and see that the files are written out with code such as:

let boolTest: Bool = !FileManager.default.fileExists(atPath: testUrl!.path, isDirectory: nil)
print("!file exist: \(boolTest)")

In the "Signing & Capabilities" tab of my Target under iCloud I have clicked "iCloud Documents" and have a container called iCloud.myAppName that is assigned to my Team. (Note: There are two other checks "Key-value storage" and "CloudKit". I have tried those both ways. I believe they should be unchecked.)

Regardless, all seems to work well. I can see through the fileExist that it is written. However, I cannot see the documents in the File app or pull up the documents through the app. Only the documents on the device.

At this point, I am not sure what I am missing. Nor do I have any ideas as to how to debug this.

jz_
  • 338
  • 2
  • 14
  • I have the exactly same problem? What as the solution? – Andrei Matei Mar 10 '21 at 07:21
  • Never solved it. One of the many problems that led me to realize I was not going to accomplish what I wanted to do (and perhaps why there are few apps that do this). I moved on to other things. – jz_ Mar 10 '21 at 11:30

1 Answers1

0

Save them within the Documents folder in cloud container. No need to add .appendingPathComponent("myAppName")

jki
  • 4,617
  • 1
  • 34
  • 29