10 Replies
      Latest reply on Jun 10, 2019 7:11 AM by aiwen324
      ehmjaysee Level 1 Level 1 (0 points)

        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.

        • Re: Files are not visible on the iCloud Drive
          ehmjaysee Level 1 Level 1 (0 points)

          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. 

            • Re: Files are not visible on the iCloud Drive
              coreymcc Level 1 Level 1 (0 points)

              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.

            • Re: Files are not visible on the iCloud Drive
              JoePasadena Level 1 Level 1 (0 points)

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

                • Re: Files are not visible on the iCloud Drive
                  ehmjaysee Level 1 Level 1 (0 points)

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

                      }

                • Re: Files are not visible on the iCloud Drive
                  JoePasadena Level 1 Level 1 (0 points)

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