My Enviroinment:
xcode 8.2.1
Swift 3.0
MacOS 10.12.3
Maybe I misunderstand how iCloud Drive is designed to work. My iPhone app will create files and store them in the app's ubiquitous file folder so they should appear in the icloud drive on the mac or PC. However the files are not visible with the mac finder even though the files do exist in the mac filesystem. More on this later.
Here is my code to create the file:
let containerURL = FileManager.default.url(forUbiquityContainerIdentifier: nil)
let documentDirectoryURL = containerURL!.appendingPathComponent("Documents")
let documentURL = documentDirectoryURL.appendingPathComponent("myFile.txt")
let text = String("test message")
text.write(to: documentURL, atomically:true, encoding:String.Encoding.utf8)
You can see I am using the app's default ubiquity container URL and appending the folder "Documents" and appending a filename. The app runs without any errors and I can confirm the file is created and viewable from the iCloud Drive app on the phone. In fact the iCloud Drive app on the iPhone will show me the correct folder name as I defined it with NSUbiquitousContainerName. I can also view this file on the Mac in a couple ways:
1) Using the terminal program on the Mac I can see the file is created and updated correctly at this path: /Users/mjc/Library/Mobile Documents/iCloud~com~mchartier~motoproto1/Documents/myFile.txt
2) Using the Mac Finder I can see the file when I click on "All My Files".
However I do not see the file or the app's ubiquitous folder when I click on "iCloud Drive" on the Finder. Nor do I see anything on icloud.com or on my PC running iCloud software.
Here is another weird behavior: Open the Finder and click on "all my files" and I see my file. Right click on the file and select "show in containing folder" and now I see my file appear with the full path to the file as you would expect. So far so good. Now when I click on "iCloud Drive" I see a new folder appear called "TextEdit" which was never there before. Now when I click on TextEdit I can see my file appear and I can open and view file contents. However, I still do not see anything on icloud.com
I have iCloud enabled in my xcode project capabilities and I have my entitlements setup correctly as far as I can tell. I am using the default ubiquity container. I increased my build number each time I changed info.plist to make sure the settings will take affect. Here are relevant lines from info.plist :
<key>NSUbiquitousContainers</key>
<dict>
<key>iCloud.com.mchartier.motoproto1</key>
<dict>
<key>NSUbiquitousContainerIsDocumentScopePublic</key>
<true/>
<key>NSUbiquitousContainerName</key>
<string>MotoProto1</string>
<key>NSUbiquitousContainerSupportedFolderLevels</key>
<string>None</string>
</dict>
</dict>
So to summarize: My ubiquitous folder is not ubiquitous at all. The files created on the iPhone can only be viewed correctly by using the iCloud drive app on the phone itself. The files are clearly sent into the iCloud because they show up on the Mac filesystem but my app's ubiquity folder will not show up in the iCloud Drive folder in the Finder.