Files are not visible on the iCloud Drive

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.

Some progress!


So I created a new project to start back at the beginning. I went through all the steps to enable iCloud capability in my app, create new provision profiles and entitlements, and create all the entires in the info.plist file. Then I ran the exact same code to create the file this time the file is visible from the Mac Finder in the top-level iCloud folder. Yeah.


The weird part is that my folder from the first project is now visible as well! Must be a strange bug in xcode or iCloud because now both projects are able to create files in the icloud drive and they are visible on the mac as well as icloud.com.


Unfortunately the PC is still not showing the new files/folders in the icloud folder. Maybe it just takes longer to sync.

I was experiencing nearly the same issue. I could copy a PDF from local storage to my default ubiquitous container on iCloud Drive, and I could view this file in the Files app under my app folder in the iCloud Drive location. However, my app folder would not appear in either Finder or iCloud.com. On my Mac, I could use Terminal to find the (container)/Documents folder under the Library/Mobile Documents folder.


Unlike you, this folder in Terminal was always empty of any files. I tried so much troubleshooting but eventually tried your workaround. I created a new project with a new iCloud Drive container and wrote a file to it. Now, my other's app's container and its documents are showing up everywhere, including Files, Finder, and iCloud.com, and new files are syncing immediately!


Weirdly, I cannot see the container for my new test app yet, but that's OK, I suppose, for now.


I just wanted to say thanks, and let you know that your idea of using a second new project somehow worked to get my real app's folder syncing too.

May we know what's the final solution for this issue? Thanks.

Hard to say exactly how the problem was resolved. There was a lot of trial-and-error and eventually the problem went away. One possibility is that the /Documents folder was not yet crated in the ubiquitous folder when the app was trying to create files. The code below will make sure the folder exists:


// First get the URL for the default ubiquity container for this app

if let containerURL = fm.url(forUbiquityContainerIdentifier: nil) {

let tryURL = containerURL.appendingPathComponent("Documents")

do {

if (fm.fileExists(atPath: tryURL.path, isDirectory: nil) == false) {

try fm.createDirectory(at: tryURL, withIntermediateDirectories: true, attributes: nil)

}

documentsURL = tryURL

} catch {

log.error("ERROR: Cannot create /Documents on iCloud")

}

} else {

log.error("ERROR: Cannot get ubiquity container")

}

I have this Documents folder code already.

The file exists on iCloud->Manage Storage->AppName on my iPhone,

but it can't be shown on my MacBook Pro or iCloud.com

in Macbook Pro, in Finder, how to see "All my Files"?

What's the ubiquitous sub folder name for the iCloud Drive Documents?

the app name?

iCloudDrive\Documents\AppName\??

In MacOS High Sierra Apple removed "all my files" and now there is a similar feature called "recents". You can find this by going into Finder preferences --> sidebar. Once you turn that on you should see your iCloud files show up in the recents list. Right click on any file to see the full path.

no, the file wasn't on Macbook Pro Recent, it only resided on iPhone->iCloud->Manage Storage->AppName

Hi, I have the same issue. Have you solved this problem?

I have issues also related to this issue, basically in the same form. I'm really frustrated by iCloud rarely working as advertised and providing very little info as to why issues are occurring.

I can navigate to the files created via Finder to the Mobile Documents folder of my simulator, but they never show up in the Files app in the simulator. None of the .plist entries given above seem to do anything in terms of what might be seen in the UI.

For example, when I go into settings and iCloud, it does know that files associated with my app are in iCloud.
I have the same issue. Has anyone solved this problem?

I have the Same Isabell. I am also looking for a solution!

Just update your project Build Version and run again.

Yep, same problem here. None of the solutions worked for me so far, bumping Build Version, uninstalling, rebooting.

Nothing will get the documents to appear in Finder/Files although I can see them listed in "Mobile Documents/iCloud.container".

Sad state of affairs Apple, please fix this.

Files are not visible on the iCloud Drive
 
 
Q