15

I am trying to use iCloud Documents to store XML files from my iOS App. Everything seems to be working fine (I can write and read files without errors) except my App's files do not show up in iCloud Documents neither in icloud.com nor in developer.icloud.com nor on my Windows PC in iCloud Drive folder. I was running the app in simulator and tested with TestFlight on a real device. I have the latest version of iCloud for Windows 4.0 installed. The App is created in Xcode 6.

Does anyone know how to make the files appear in iCloud Documents?

The code I am using for the saving the file:

NSLog(@"Syncing with iCloud");
    NSURL *ubiq = [filemgr URLForUbiquityContainerIdentifier:nil];
    if (ubiq) {
        NSURL *ubiquitousPackage = [ubiq URLByAppendingPathComponent:@"Documents" isDirectory:YES];
        if ([filemgr fileExistsAtPath:[ubiquitousPackage path]] == NO)
            [filemgr createDirectoryAtURL:ubiquitousPackage
              withIntermediateDirectories:YES
                               attributes:nil
                                    error:nil];

        ubiquitousPackage = [ubiquitousPackage URLByAppendingPathComponent:@"data.pxa"];

        DataFile *file = [[DataFile alloc] initWithFileURL:ubiquitousPackage];
        file.xmlContent = doc.XMLString;
        [file saveToURL:[file fileURL] forSaveOperation:UIDocumentSaveForCreating | UIDocumentSaveForOverwriting completionHandler:^(BOOL success) {

            if (success) {
                NSLog(@"Synced with iCloud: %@", [ubiquitousPackage path]);

            } else {
                NSLog(@"Syncing with iCloud failed");
            }
        }];
    } else {
        NSLog(@"iCloud not available");
    }
Nostradamus
  • 668
  • 6
  • 18
  • FWIW, I don't bother trying to create the container directory, and it works fine. – Taylor Feb 03 '15 at 19:59
  • 4
    Make sure you bump your version and build number for info.plist changes to take effect. – Steve Moser Feb 18 '16 at 16:40
  • @SteveMoser thanks a lot for this, it solved my problem - I was worried it's something to do with iCloud or my code not accounting for some use case, but it was really as easy as this. – CristianMoisei Sep 02 '19 at 23:50
  • @SteveMoser would it make sense to put your version bump as an answer? It just worked for me but I missed it last time I was on this question! – Michael Forrest Oct 18 '19 at 10:11

2 Answers2

5

I found out what the problem was: The key in Info.plist for the iCloud container was a bit different from the format "iCloud.com.example.MyApp".

Nostradamus
  • 668
  • 6
  • 18
-3

I follow instructions at this link to see files created by my app in iCloudDrive. I can see file from settings>iCloud>Storage from device. Hope it helps.

Totka
  • 627
  • 6
  • 24