【问题标题】:Why my app is not shown in iCloud Drive Folder为什么我的应用程序未显示在 iCloud Drive 文件夹中
【发布时间】:2015-08-03 20:11:42
【问题描述】:

iCloud Drive 文件夹不显示我的应用程序的文件夹。

这是我将文件发送到 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];
}

其实我做了所有解释in this post

一切看起来都很好。我可以成功上传文件,我可以通过终端在我的电脑上显示它们。

我可以看到我刚刚从我的 iphone 上传的文件。

但我的 Mac 或 icloud.com 中的 iCloud Drive 文件夹中没有显示任何内容。为什么他们没有显示我的应用程序的文件夹,即使一切看起来都很好并且没有错误?

【问题讨论】:

    标签: ios icloud icloud-drive


    【解决方案1】:

    我在 swift 中尝试了相同的代码并遇到了同样的问题。

    这对我有用:

    1) 在 info.plist 源代码中找到以下几行

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

    2) 增加版本号。如果是 1,则将其增加到 2。无论版本号是什么,都执行相同的操作。

    3) 如果需要,请从您的设备上卸载该应用程序,然后按照上述两个步骤重新运行它

    【讨论】:

    • 奇怪但工作......
    【解决方案2】:

    在现有应用程序中唯一对我有用(我遇到完全相同的问题)(因此我无法更改捆绑 ID)是在 URLForUbiquityContainerIdentifier 文件夹下创建一个 Documents 子文件夹并写入所有我的文件在那里。

    一旦我这样做了,它们就会出现在我 Mac 上的 Finder 中。但是它们没有出现在 iCloud Drive 中我的应用文件夹的 Documents 子文件夹中,它们直接出现在应用文件夹中。

    【讨论】:

    • 您先生是个学者 :)。如果创建一个非默认容器,您需要在其中创建一个 Documents 文件夹。该文档文件夹不会显示给最终用户,但该文件夹中的内容会显示。 :)
    • 这在昨晚有效。但是今天,应用程序文件夹不再显示在 iCloud Drive... :(
    【解决方案3】:

    但我的 Mac 或 icloud.com 中的 iCloud Drive 文件夹中没有显示任何内容。 为什么他们没有显示我的应用程序的文件夹,即使一切看起来都像 很好,没有错误?

    这是一个新应用还是新创建的 iCloud 容器? 那么原因是:NSUbiquitousContainerIsDocumentScopePublic=true 只有在应用(以及授权的 iCloud 容器)通过审核和批准后才生效。

    我不记得我在哪里读到了“丢失的信息”(至少我没有从 Apple 文档中得到它)。

    我的另一个例子似乎证明了这一点:在现有的应用程序中(使用“旧样式 - TeamIdentifierPrefix”iCloud 容器),我可以使该容器在 iCloud 驱动器上可见。但是一个新的容器在 iCloud Drive 中“对公众”是不可见的(即使我在我的 Mac 上使用 Terminal.app 也能看到它)。一旦应用(带有新容器)获得批准并在 AppStore 上可用,您就可以再次使用 Info.plist(并使新容器可见/隐藏,...)

    【讨论】:

    • 我似乎反驳了您的说法,即“NSUbiquitousContainerIsDocumentScopePublic=true 仅在应用程序(以及授权的 iCloud 容器)经过审查和批准后才生效”。对于现有的应用商店应用,plist 中没有 NSUbiquitousContainers 键。我添加了 NSUbiquitousContainerIsDocumentScopePublic=true,并在没有提交到应用商店的情况下增加了 CFBundleVersion - 并且 ubiquity 容器在 iCloud Drive iOS 应用程序中变得可见并且该容器在登录到同一个 iCloud 的 OS X 系统上变得可见帐户(我什至没有同步文件)。
    • 我同意@Michael Rourke。它与 App Store 没有任何关系。为我解决的问题是根据stackoverflow.com/questions/25203697/… 获得一个新的应用程序 ID。我的应用还没有在 App Store 中。在第一次运行应用程序之前,您需要在 Info.plist 中设置 NSUbiquitousContainerIsDocumentScopePublic=true。
    • 我也遇到了同样的问题。我的应用程序已经存在于应用程序商店中,所以我无法让应用程序文件夹在 iCloud Drive 中可见。我什至卸载了应用程序并重新安装,它没有显示。
    【解决方案4】:
    1. 在 Info.plist 中添加 CFBundleVersion。
    2. https://developer.apple.com/account/ios/identifier/cloudContainer 上创建一个新的 iCound 容器
    3. 在 Xcode 中指定自定义容器。取消勾选旧容器并勾选新创建的容器。

    【讨论】:

      【解决方案5】:

      对我来说,忘记在应用程序的info.plist 中为新容器添加上述条目。

      【讨论】:

        猜你喜欢
        • 2017-07-03
        • 1970-01-01
        • 2022-07-15
        • 2021-06-24
        • 2016-01-07
        • 1970-01-01
        • 2020-08-07
        • 1970-01-01
        • 2016-02-26
        相关资源
        最近更新 更多