我正在开发一个支持iCloud的应用程序,用户可以通过iCloud Drive导入和导出文件.在浏览iCloud Drive时,无论是使用UIDocumentPickerViewController(iOS 8)还是Finder(OS X Yosemite),我都可以看到其他支持iCloud-Drive的应用创建/拥有的目录,例如Automator,Keynote或TextEdit.
我希望我们的应用程序也能在iCloud Drive中公开其无处不在的文档目录,但还未能弄明白.在上述某些应用程序的Info.plist文件中,我发现了这个密钥:
<key>NSUbiquitousContainers</key>
<dict>
<key>com.apple.TextEdit</key>
<dict>
<key>NSUbiquitousContainerIsDocumentScopePublic</key>
<true/>
<key>NSUbiquitousContainerSupportedFolderLevels</key>
<string>Any</string>
</dict>
</dict>
Run Code Online (Sandbox Code Playgroud)
这些密钥也在这里记录,但我没有找到更广泛主题的任何其他文档.编辑/注意:虽然它不包含我的问题的答案,但文档选择器编程指南是一个有用的资源.
我已经尝试将上述键/值添加到我们的应用程序,但没有看到任何影响.我注意到/尝试过的事情:
对于第三方应用程序,iCloud容器以这种方式构建:iCloud.$(CFBundleIdentifier).我不确定为什么TextEdit只使用纯包标识符,但对于我们的标识符,我尝试了两种方法,即有和没有iCloud.前缀.我还认识到你需要对包标识符进行硬编码(即,不要使用iCloud.$(CFBundleIdentifier)),因为只有PLIST的值似乎在构建时解析,而不是键.
我以编程方式(to <containerPath>/Documents)添加了一个子目录,因此容器不为空.但是,这并不重要,因为所有其他应用程序的目录最初都是空的.
出现在iCloud Drive中的某些Apple应用程序中没有这些条目Info.plist,例如Numbers和Pages.
iCloud设置正确,我可以使用返回的URL以编程方式查看ubiquity容器[[NSFileManager defaultManager] URLForUbiquityContainerIdentifier:nil];.
我登录到启用了iCloud Drive的iCloud帐户.我可以看到我的iCloud Drive内容UIDocumentPickerViewController.
我使用iOS 8 beta 5模拟器(和Yosemite beta 5来查看Mac上的iCloud Drive目录)(编辑/注意:这同样适用于beta 6)
这就是我的Entitlements文件的样子(仅限相关部分)
<key>com.apple.developer.icloud-container-identifiers</key>
<array>
<string>iCloud.$(CFBundleIdentifier)</string>
</array>
<key>com.apple.developer.icloud-services</key>
<array>
<string>CloudDocuments</string>
</array>
<key>com.apple.developer.ubiquity-container-identifiers</key>
<array/>
Run Code Online (Sandbox Code Playgroud)
我已经在Capabilities部分使用Xcode的UI进行了设置.我不明白为什么最后一个键没有条目,但添加<string>iCloud.$(CFBundleIdentifier)</string>没有帮助.相反,它使Xcode在Capabilities UI中抱怨,所以我删除了它.编辑/注意: …
iCloud Drive Folder不显示我的应用程序的文件夹.
这是我将文件发送到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. …Run Code Online (Sandbox Code Playgroud) 有没有办法让我的文档目录与iCloud同步?
我已设置所有权限和权利,但不知道下一步该做什么.
您能否提供一个快速的代码片段或指向我应该指向的方向?
我已经尝试了两天多来写一个文件到iCloud驱动器.我尝试直接编写一个简单的文本文件,然后在本地移动它,使用UIDocumentMenuViewController等.我没有得到任何错误的代码和单步执行调试器,它看起来很成功,但当我检查文件是否存在或至少iCloud目录,那里什么都没有.我尝试了模拟器和我的iPhone,触发了iCloud同步,以及我能想到的其他一切.
我的主要目标是简单地将文本文件写入iCloud驱动器,后来将成为"数字"文件
我已经设置了我的plist文件和我的权利:
<key>NSUbiquitousContainers</key>
<dict>
<key>iCloud.com.paul.c.$(PRODUCT_NAME:rfc1034identifier)</key>
<dict>
<key>NSUbiquitousContainerIsDocumentScopePublic</key>
<true/>
<key>NSUbiquitousContainerName</key>
<string>myCloudTest</string>
<key>NSUbiquitousContainerSupportedFolderLevels</key>
<string>Any</string>
</dict>
</dict>
Run Code Online (Sandbox Code Playgroud)
我还提到了捆绑版本,如下所述:将iOS 8文档保存到iCloud Drive
我已经尝试了几十个没有运气的教程.我的最新代码基于此示例:https://medium.com/ios-os-x-development/icloud-drive-documents-1a46b5706fe1
这是我的代码:
@IBAction func ExportFile(sender: AnyObject) {
var error:NSError?
let iCloudDocumentsURL = NSFileManager.defaultManager().URLForUbiquityContainerIdentifier(nil)?.URLByAppendingPathComponent("myCloudTest")
//is iCloud working?
if iCloudDocumentsURL != nil {
//Create the Directory if it doesn't exist
if (!NSFileManager.defaultManager().fileExistsAtPath(iCloudDocumentsURL!.path!, isDirectory: nil)) {
//This gets skipped after initial run saying directory exists, but still don't see it on iCloud
NSFileManager.defaultManager().createDirectoryAtURL(iCloudDocumentsURL!, withIntermediateDirectories: true, attributes: nil, error: nil)
}
} …Run Code Online (Sandbox Code Playgroud) icloud ×4
icloud-drive ×2
ios ×2
swift ×2
entitlements ×1
icloud-api ×1
info-plist ×1
ios8 ×1
objective-c ×1
uidocument ×1