Why my app is not shown in iCloud Drive Folder

北慕城南 提交于 2019-11-27 01:38:09

问题


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.

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?


回答1:


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




回答2:


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.




回答3:


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




回答4:


  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.


来源:https://stackoverflow.com/questions/30385940/why-my-app-is-not-shown-in-icloud-drive-folder

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!