0
votes

I am trying to accomplish the following:

  1. Read a .csv file from iCloud drive that was placed there using the Mac. This works using UIDocumentPickerViewController.
  2. Process the file in iOS - this works fine
  3. Create the documents directory for my App in iCloud drive such that it is visible from the Mac - NOT working
  4. Write/Save the processed file out to the UbiquityContainer such that it is visible on the Mac. - NOT working.

I have this set to create the documents directory.

    override func viewDidLoad() {
    super.viewDidLoad()

    // Do any additional setup after loading the view, typically from a nib.
    if let iCloudDocumentsURL = FileManager.default.url(forUbiquityContainerIdentifier: nil)?.appendingPathComponent("Documents") {
        if (!FileManager.default.fileExists(atPath: iCloudDocumentsURL.path, isDirectory: nil)) {
            do {
                try FileManager.default.createDirectory(at: iCloudDocumentsURL, withIntermediateDirectories: true, attributes: nil)
                print("Created Directory at \(iCloudDocumentsURL)")
            } catch {
                print("Error Creating Directory: \(error)")
            }
        }
        print("\(#function):\(#line) iCloudDocumentsURL =\n\(iCloudDocumentsURL)")
        self.iCloudDocumentsURL = iCloudDocumentsURL
    }

I have the entitlements turned on and a plist entry as follows:

<dict>
<key>iCloud.com.mycompany.SubLunch</key>
<dict>
    <key>NSUbiquitousContainerIsDocumentScopePublic</key>
    <true/>
    <key>NSUbiquitousContainerName</key>
    <string>SubLunch</string>
    <key>NSUbiquitousContainerSupportedFolderLevels</key>
    <string>One</string>
</dict>

I can see the file is getting written here:

file:///private/var/mobile/Library/Mobile%20Documents/iCloud~com~mycompany~SubLunch/Documents/LRA%20Order%20Detail%20Results.csv

But nothing changes on my iCloud Drive on my Mac.

I have used brctl log --wait --shorten to view activity and I can see output.

What am I doing wrong here?

Thanks in advance

1
Rob, A solution perhaps would be to write a daemon that runs under OS X on your Mac that your iOS app talks too. The daemon would surely be able to write to the OS X iCloud drive.user3069232

1 Answers

0
votes

I found the answer, you need to export to server the file once you're done modifying it. Then you will get the document picker to allow you to pick where to store it in iCould Drive.