【发布时间】:2015-11-27 08:25:54
【问题描述】:
我一直在尝试使用 iCloud 示例代码和教程来开发我们的 MacOS 和 iOS 产品之间的同步系统。在 iOS 端,我构建和运行在 iCloud Documents 容器中操作数据的代码没有问题,但在 MacOS 端,使用 Apple MacOS PackagedDocument 示例项目,我无法成功将任何数据放在我的 iCloud 中。我相信基本问题是找不到我的应用程序的 URLForUbiquityContainerIdentifier,可能是由于 iCloud 权利规范中的一些错误。但是,花了很多时间摆弄开发者门户和 Xcode 6/PackagedDocument 设置后,我一直无法找到问题的根源。
我的 iCloud 帐户以前是 MobileMe 帐户,用于在 MacOS 和 iOS 设备之间同步 Apple 应用程序,所以我相信我的 iCloud 帐户可以正常工作。
在这里,我说明了我指定调用以获取 iCloud Documents 容器的不同方式。无论如何指定,获取 iCloud 容器 URL 的调用都会返回 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 的代码,但在尝试获取 ubiquity 容器时得到相同的 nil 结果:
- (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 权利规范和/或访问 iCloud 文档容器所需的其他规范有关。如果有人对我可能发生的事情有所了解,我将非常感谢他们的反馈。如果做不到这一点,也许有人可以指点我工作 non-iOS,macos iCloud Documents 示例代码。
其他信息
我在控制台日志 PackagedDocument 启动中看到以下消息:
9/2/15 5:19:11.966 PM taskgated-helper[14145]:未满足权利 com.apple.developer.ubiquity-container-identifiers
9/2/15 5:19:11.966 PM taskgated-helper[14145]:不满足权利 com.apple.developer.icloud-container-identifiers
9/2/15 5:19:11.966 PM taskgated-helper[14145]:未满足权利 com.apple.developer.ubiquity-container-identifiers
9/2/15 5:19:11.966 PM taskgated-helper[14145]:不满足权利 com.apple.developer.icloud-container-identifiers
9/2/15 5:19:11.966 PM taskgated-helper[14145]:未满足权利 com.apple.developer.ubiquity-container-identifiers
9/2/15 5:19:11.966 PM taskgated-helper[14145]:不满足权利 com.apple.developer.icloud-container-identifiers
9/2/15 5:19:11.967 PM taskgated-helper[14145]:由于配置文件允许 pid=14144 的权利
更多信息
我使用一个有效的 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。
我想这意味着它仍然是某种权利问题。
更多信息
我进行了另一个实验,我从我常用的开发人员系统(Yosemite 10.10.5)的 Xcode 6.4/Preferences/Actions/Export Accounts... 中导出了我的开发人员身份,然后在 Mavericks 10.9.5 下重新启动了我的 MacBook Pro并使用 Xcode 6.1/Preferences/Actions/ Import Accounts... 导入身份。 (Mavericks 系统盘实际上是我升级到 Yosemite 之前 MacBook Pro 系统盘的 Carbon Copy。)现在,当我在 Mavericks 中构建和运行 PackagedDocument 时,一切正常 em>.
然后我重新启动回到 Yosemite 并删除我的身份并使用 Xcode 6.1/Preferences/Actions/Import Accounts...导入身份。现在,当我在 Yosemite 中构建并运行 PackagedDocument 时,它仍然无法工作——找不到 iCloud 容器。
然后我决定在全新安装的 El Capitan (10.11 Beta 5)/Xcode 6.4 中尝试相同的实验。同样,它仍然无法正常工作--找不到 iCloud 容器。
最后,我决定再做一个实验。我决定尝试打开 iCloud Drive。但是,因为我不想将我的工作 iCloud 帐户转换为 iCloud Drive,我决定为测试创建一个新的 iCloud ID,并打开 iCloud Drive。现在,当我使用 iCloud Drive 在 El Capitan 中构建和运行 PackagedDocument 时,一切正常。
【问题讨论】:
-
App SandBox 授权是否开启?此链接中的示例应用程序使用 iCloud 容器,因此您可以尝试构建并验证 OSX 应用程序是否可以访问 iCloud 容器。请注意,您还可以使用 OSX 上的命令提示符查看 iCloud 容器中的内容。 ossh.com.au/design-and-technology/software-development/…
-
是的,沙盒权利已开启,用户选择的文件具有读/写权限和访问权限。
-
感谢您的回复。我可以通过 System Preferences.../iCloud/Manage... 查看我使用 iOS iCloud 示例应用程序创建的 iCloud 容器数据,但 PackagedDocument 中没有出现这样的 iCloud 容器。我不介意知道那个命令提示符是什么。
-
只需打开命令提示符(终端)并运行此
ls "Library/Mobile Documents/"。您应该会看到所有应用程序 iCloud 容器的列表。然后只需将容器名称添加到上述命令的末尾即可列出其内容。添加-R选项以递归地列出内容,例如ls -R "Library/Mobile Documents/iCloud~au~com~ossh~iWallet2" -
您使用的是什么版本的 OSX、iOS 和 XCode - 如果它是最新的测试版,请确保您使用的是所有内容的最新测试版,尤其是 XCode。
标签: xcode macos icloud documents entitlements