amone
amone

Reputation: 3862

Why my app is not shown in iCloud Drive Folder

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?

Upvotes: 20

Views: 10477

Answers (6)

akaDuality
akaDuality

Reputation: 406

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>

Upvotes: 1

Thompsonmachine
Thompsonmachine

Reputation: 177

Info.plist example

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

Upvotes: 1

webcpu
webcpu

Reputation: 3432

  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.

Upvotes: 2

Afaq Ahmad
Afaq Ahmad

Reputation: 133

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

Upvotes: 12

Joris
Joris

Reputation: 6306

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.

Upvotes: 8

J&#252;rg Otter
J&#252;rg Otter

Reputation: 77

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, ...)

Upvotes: 6

Related Questions