为什么 Apple 的 PackagedDocument MacOS iCloud 示例项目找不到 URLForUbiquityContainerIdentifier?

Why does Apple's PackagedDocument MacOS iCloud sample project not find URLForUbiquityContainerIdentifier?

我一直在试验 iCloud 示例代码和教程,以便在我们的 MacOS 和 iOS 产品之间开发一个同步系统。在 iOS 方面,我在构建和 运行 处理 iCloud 文档容器中数据的代码方面没有问题,但在 MacOS 方面,使用 Apple MacOS PackagedDocument 示例项目,我无法成功地将任何数据放入我的 iCloud。我相信基本问题是找不到我的应用程序的 URLForUbiquityContainerIdentifier,这可能是由于 iCloud 权利规范中的一些错误。但是,在花了很多时间摆弄开发者门户和 Xcode 6/PackagedDocument 设置之后,我一直无法找到来源的问题。

我的 iCloud 帐户以前是 MobileMe 帐户,用于在 MacOS 和 iOS 设备之间同步 Apple 应用程序,所以我相信我的 iCloud 帐户没有问题。

在这里,我将说明我指定调用以获取 iCloud 文档容器的不同方式。获取 iCloud 容器的调用 URL returns nil 不管它是如何指定的:

    // remember our ubiquity container NSURL for later use
    _ubiquityContainer = [[NSFileManager defaultManager] URLForUbiquityContainerIdentifier:@"icloud.com.mycompany.PackagedDocument"];
    _ubiquityContainer = [[NSFileManager defaultManager] URLForUbiquityContainerIdentifier:@"7G3Z4SV5WT.com.mycompany.PackagedDocument"];
    _ubiquityContainer = [[NSFileManager defaultManager] URLForUbiquityContainerIdentifier:nil];

在我的 iOS 实验中,此 URLForUbiquityContainerIdentifier 调用总是获得所需的 URL.

应用程序的 CFBundleIdentifier 是 com.mycompany.PackagedDocument

iCloud 授权密钥指定如下:

com.apple.application-identifier键值为$(TeamIdentifierPrefix)com.mycompany.PackagedDocument

com.apple.developer.icloud-services键值为CloudDocuments

com.apple.developer.icloud-container-identifiers键值为 iCloud.$(CFBundleIdentifier)

com.apple.developer.ubiquity-container-identifiers 键值是 iCloud.$(CFBundleIdentifier)

我也尝试了这个 video tutorial 中的代码,但是在尝试获取无处不在的容器时得到了相同的零结果:

    - (IBAction)saveToIcloud:(id)sender {

    NSFileManager *fm = [NSFileManager defaultManager];

    NSURL *directory = [[fm URLForUbiquityContainerIdentifier:@"7G3Z4SV5WT.com.mycompany.PackagedDocument"]
        URLByAppendingPathComponent:@"Documents"];
    directory = [[fm URLForUbiquityContainerIdentifier:@"iCloud.com.mycompany.PackagedDocument"]
                        URLByAppendingPathComponent:@"Documents"];
    directory = [[fm URLForUbiquityContainerIdentifier:nil]
                        URLByAppendingPathComponent:@"Documents"];
    directory = [[fm 

    if (directory) {
        [fm createDirectoryAtURL:directory withIntermediateDirectories:NO attributes:nil error:NULL];

        NSURL *filepath = [NSURL URLWithString:@"/Users/leg/Desktop/myjpeg.jpg"];

        NSURL *destination = [directory URLByAppendingPathComponent:[filepath lastPathComponent]];

        [fm setUbiquitous:YES itemAtURL:filepath destinationURL:destination error:nil];
    }
}

总而言之,我认为问题一定与我的 iCloud 权利规范有关 and/or 访问 iCloud 文档容器所需的其他规范。如果有人知道我可能会发生什么,我将非常感谢他们的反馈。如果做不到这一点,也许有人可以指点我工作 non-iOS,macos iCloud 文档示例代码。

附加信息

我在控制台日志 PackagedDocument 启动中看到以下消息:

9/2/15 5:19:11.966 PM taskgated-helper[14145]: unsatisfied entitlement com.apple.developer.ubiquity-container-identifiers

9/2/15 5:19:11.966 PM taskgated-helper[14145]: unsatisfied entitlement com.apple.developer.icloud-container-identifiers

9/2/15 5:19:11.966 PM taskgated-helper[14145]: unsatisfied entitlement com.apple.developer.ubiquity-container-identifiers

9/2/15 5:19:11.966 PM taskgated-helper[14145]: unsatisfied entitlement com.apple.developer.icloud-container-identifiers

9/2/15 5:19:11.966 PM taskgated-helper[14145]: unsatisfied entitlement com.apple.developer.ubiquity-container-identifiers

9/2/15 5:19:11.966 PM taskgated-helper[14145]: unsatisfied entitlement com.apple.developer.icloud-container-identifiers

9/2/15 5:19:11.967 PM taskgated-helper[14145]: allowing entitlement(s) for pid=14144 due to provisioning profile

更多信息

我用一个有效的 iOS iCloud 示例项目进行了实验,以验证 PackagedDocument iCloud 容器:

我将 iOS 示例的 Capabilites/iCloud 设置从“使用默认容器”更改为“指定自定义容器”。我检查了示例的默认容器并检查了“iCloud.com.mycompany.PackagedDocument”。

然后我更改了 URLForUbiquityContainerIdentifier 调用:

    from:  NSURL *baseURL = [[NSFileManager defaultManager]URLForUbiquityContainerIdentifier:nil];

    to:    NSURL *baseURL = [[NSFileManager defaultManager] URLForUbiquityContainerIdentifier:@"iCloud.com.mycompany.PackagedDocument"];

现在,当我 运行 这个 iOS 应用程序时,它会创建 PackagedDocument iCloud 容器并将其用于其数据——这正是我一直试图对 PackagedDocument MacOS 示例所做的.

然后我回到 MacOS PackagedDocument 项目并 运行 它以查看 URLForUbiquityContainerIdentifier 调用现在是否可以找到容器。它没有。即使容器现在确实存在,仍然返回 Nil。

我想这意味着它仍然是某种权利问题。

更多信息

  1. 我进行了另一个实验,从 Xcode 6.4/Preferences/Actions/Export 账户中导出了我的开发者身份……我常用的开发者系统(Yosemite 10.10.5, ) 然后在 Mavericks 10.9.5 下重新启动我的 MacBook Pro,并使用 Xcode 6.1/Preferences/Actions/ Import Accounts… 导入身份。 (Mavericks 系统盘实际上是我升级到 Yosemite 之前我的 MacBook Pro 系统盘的 Carbon Copy。)现在,当我构建和 运行 PackagedDocument在 Mavericks,一切正常

  2. 然后我重新启动回到 Yosemite 并删除了我的身份并使用 Xcode 6.1/Preferences/Actions/ 导入帐户…导入身份。现在,当我在 Yosemite 中构建 运行 PackagedDocument 时,它仍然不起作用--找不到 iCloud 容器.

  3. 然后我决定在全新安装的 El Capitan (10.11 Beta 5)/Xcode 6.4 中尝试相同的实验。还是不行——找不到iCloud容器.

  4. 最后,我决定再试一次。我决定尝试打开 iCloud Drive。但是,因为我不想将我的工作 iCloud 帐户转换为 iCloud Drive,我决定创建一个新的 iCloud ID 进行测试,并打开 iCloud Drive 。现在,当我使用 iCloud Drive 在 El Capitan 中构建 运行 PackagedDocument 时, 一切正常.

为什么 Apple 的 PackagedDocument MacOS iCloud 示例项目找不到 URLForUbiquityContainerIdentifier?

我在问题末尾添加的 更多信息 让我得出结论,现在需要 iCloud Drive如果 MacOS 大于 10.9 (Mavericks),即 Yosemite 或 El Capitan,则非苹果应用程序可以访问 iCloud 容器。也就是说,URLForUbiquityContainerIdentifier 不会在纯 iCloud Yosemite 或 El Capitan 中找到。我认为 PackagedDocumentiCloud Drive 之前的 Mavericks 中运行良好并且似乎在 iCloud Drive 中运行良好很重要 El Capitan,(但不是在普通 iCloud El Capitan 中。)

我想一定有一些机制可以让普通的 iCloud 使用 pre-Yosemite 应用程序,这样他们仍然可以创建和访问他们的 iCloud 个容器,但我不知道它是什么。