20

iCloud Drive Folder doesn't show my app's folder.

This is how I send a file to iCloud Drive:

- (IBAction)btnStoreTapped:(id)sender {
    // Let's get the root directory for storing the file on iCloud Drive
    [self rootDirectoryForICloud:^(NSURL *ubiquityURL) {
        NSLog(@"1. ubiquityURL = %@", ubiquityURL);
        if (ubiquityURL) {

            // We also need the 'local' URL to the file we want to store
            //NSURL *localURL = [NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:@"Photo" ofType:@"pdf"]];


            NSURL *localURL = [self localPathForResource:@"document" ofType:@"doc"];
            NSLog(@"2. localURL = %@", localURL);

            // Now, append the local filename to the ubiquityURL
            ubiquityURL = [ubiquityURL URLByAppendingPathComponent:localURL.lastPathComponent];
            NSLog(@"3. ubiquityURL = %@", ubiquityURL);

            // And finish up the 'store' action
            NSError *error;
            if (![[NSFileManager defaultManager] setUbiquitous:YES itemAtURL:localURL destinationURL:ubiquityURL error:&error]) {
                NSLog(@"Error occurred: %@", error);
            }else{
                NSLog(@"Succeed");
            }
        }
        else {
            NSLog(@"Could not retrieve a ubiquityURL");
        }
    }];
}

- (void)rootDirectoryForICloud:(void (^)(NSURL *))completionHandler {

    dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
        NSURL *rootDirectory = [[[NSFileManager defaultManager] URLForUbiquityContainerIdentifier:nil]URLByAppendingPathComponent:@"Documents"];

        if (rootDirectory) {
            if (![[NSFileManager defaultManager] fileExistsAtPath:rootDirectory.path isDirectory:nil]) {
                NSLog(@"Create directory");
                [[NSFileManager defaultManager] createDirectoryAtURL:rootDirectory withIntermediateDirectories:YES attributes:nil error:nil];
            }
        }

        dispatch_async(dispatch_get_main_queue(), ^{
            completionHandler(rootDirectory);
        });
    });
}

- (NSURL *)localPathForResource:(NSString *)resource ofType:(NSString *)type {
    NSString *documentsDirectory = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES)[0];
    NSString *resourcePath = [[documentsDirectory stringByAppendingPathComponent:resource] stringByAppendingPathExtension:type];
    return [NSURL fileURLWithPath:resourcePath];
}

Actually I did everyting explained in this post

Everything looks like fine. I can upload files successfully and I can show them in my computer via terminal.

enter image description here

enter image description here

And I can see the files I just uploaded from my iphone.

But nothing shown in my iCloud Drive folder in my mac or icloud.com. Why they are not showing my app's folder even everything looks like fine and there is no error?

Community
  • 1
  • 1
amone
  • 3,712
  • 10
  • 36
  • 53

6 Answers6

12

I have tried the same code in swift and got the same problem.

This is what worked for me :

1) Find the following lines in your info.plist source code

<key>CFBundleVersion</key>
<string>1</string>

2) Increase the version number. If it is 1, increase it to 2. Do the same whatever the version number is.

3) If needed, uninstall the app from your device and re-run it after following the above two steps

A R
  • 1,412
  • 2
  • 14
  • 29
Afaq Ahmad
  • 133
  • 1
  • 10
8

The only thing that worked for me (I had exactly the same issues) in an existing app (so I can't change the bundle ID) was to create a Documents subfolder under the URLForUbiquityContainerIdentifier folder and write all my files there.

Once I did this, they appeared in Finder on my Mac. However they did not appear in a Documents subfolder of my app's folder in iCloud Drive, they appeared directly in the app folder.

Joris Mans
  • 6,024
  • 6
  • 42
  • 69
  • 1
    You sir are a scholar :). If creating a non-default container you need to create a Documents folder inside of it. that documents folder does not show to end users, but what is inside of that folder does. :) – bworby Jul 21 '17 at 05:11
  • this worked last night. But now today the apps folder is no longer showing in iCloud Drive... :( – bworby Jul 21 '17 at 19:42
6

But nothing shown in my iCloud Drive folder in my mac or icloud.com. Why they are not showing my app's folder even everything looks like fine and there is no error?

Is this a new app or a newly created iCloud container? Then the reason is: NSUbiquitousContainerIsDocumentScopePublic=true only gets in effect once the app (and the entitled iCloud container) has been gone through review and approval.

I can't remember where I read that "missing piece of information" (at least i didn't get it from the Apple documentation).

Another example from my experience, which seems to prove this: In an existing app (with the "old style - TeamIdentifierPrefix" iCloud container) i can make that container visible on iCloud drive. But a new container won't be visible in iCloud Drive "to the public" (even tough I can see it using Terminal.app on my Mac). Once the app (with the new container) has been approved and is available on the AppStore, you can play again with the Info.plist (and make the new container visible/hidden, ...)

  • 3
    I seem to have disproved your statement that 'NSUbiquitousContainerIsDocumentScopePublic=true only gets in effect once the app (and the entitled iCloud container) has been gone through review and approval'. With an existing app store app, no NSUbiquitousContainers keys in the plist. I added NSUbiquitousContainerIsDocumentScopePublic=true, and bumped CFBundleVersion without submitting to the app store - and the ubiquity container becomes visible in the iCloud Drive iOS app **and** the container become visible on an OS X system logged into the same iCloud account (I didn't even sync a file). – MichaelR Oct 15 '15 at 20:52
  • 3
    I agree @Michael Rourke. It does not have anything to do with App Store. What fixed it for me was getting a new app ID as per http://stackoverflow.com/questions/25203697/exposing-an-apps-ubiquitous-container-to-icloud-drive-in-ios-8/32801479#32801479. My app is not in App Store yet. You need to have NSUbiquitousContainerIsDocumentScopePublic=true in Info.plist before you run the app for the first time. – BillF Nov 13 '15 at 09:47
  • 2
    I have been having this same issue. My app is already live in the app store, so is there nothing I can do to have the app folder become visible in the iCloud Drive. I even uninstalled the app and reinstalled, and it does not show. – gbotha Dec 11 '15 at 15:23
2
  1. Bump CFBundleVersion in Info.plist.
  2. Create a new iCound container on https://developer.apple.com/account/ios/identifier/cloudContainer
  3. Specify custom containers in Xcode. Untick the old containers and tick the new created container.
webcpu
  • 3,174
  • 2
  • 24
  • 17
1

Info.plist example

For me it was forgetting to add the above entries in the app's info.plist for the new container.

Thompsonmachine
  • 137
  • 1
  • 6
1

My case was that I have missed that your container at Info.plist should be wrapped to NSUbiquitousContainers dictionary.

I have fixed and increase build version, the folder did appear.

<key>NSUbiquitousContainers</key>
<dict>
    <key>iCloud.com....</key>
    <dict>
        <key>NSUbiquitousContainerIsDocumentScopePublic</key>
        <true/>
        <key>NSUbiquitousContainerName</key>
        <string>The name at iCloud folder</string>
        <key>NSUbiquitousContainerSupportedFolderLevels</key>
        <string>Any</string>
    </dict>
</dict>
akaDuality
  • 384
  • 5
  • 6