【发布时间】:2014-12-05 08:56:45
【问题描述】:
我正在尝试使用 iCloud 文档来存储来自我的 iOS 应用程序的 XML 文件。一切似乎都工作正常(我可以毫无错误地写入和读取文件),除了我的应用程序的文件没有显示在 iCloud 文档中,既不在 icloud.com 也不在 developer.icloud.com 中,也不在我的 Windows PC 上的 iCloud Drive 文件夹中。我在模拟器中运行该应用程序,并在真实设备上使用 TestFlight 进行了测试。我安装了最新版本的 iCloud for Windows 4.0。该应用程序是在 Xcode 6 中创建的。
有人知道如何使文件出现在 iCloud 文档中吗?
我用于保存文件的代码:
NSLog(@"Syncing with iCloud");
NSURL *ubiq = [filemgr URLForUbiquityContainerIdentifier:nil];
if (ubiq) {
NSURL *ubiquitousPackage = [ubiq URLByAppendingPathComponent:@"Documents" isDirectory:YES];
if ([filemgr fileExistsAtPath:[ubiquitousPackage path]] == NO)
[filemgr createDirectoryAtURL:ubiquitousPackage
withIntermediateDirectories:YES
attributes:nil
error:nil];
ubiquitousPackage = [ubiquitousPackage URLByAppendingPathComponent:@"data.pxa"];
DataFile *file = [[DataFile alloc] initWithFileURL:ubiquitousPackage];
file.xmlContent = doc.XMLString;
[file saveToURL:[file fileURL] forSaveOperation:UIDocumentSaveForCreating | UIDocumentSaveForOverwriting completionHandler:^(BOOL success) {
if (success) {
NSLog(@"Synced with iCloud: %@", [ubiquitousPackage path]);
} else {
NSLog(@"Syncing with iCloud failed");
}
}];
} else {
NSLog(@"iCloud not available");
}
【问题讨论】:
-
FWIW,我不费心去创建容器目录,它工作正常。
-
确保更新版本和内部版本号以使 info.plist 更改生效。
-
@SteveMoser 非常感谢,它解决了我的问题 - 我担心这与 iCloud 或我的代码没有考虑某些用例有关,但它真的就这么简单。
-
@SteveMoser 将您的版本提升作为答案是否有意义?它只是对我有用,但我上次在这个问题上错过了它!
标签: ios objective-c xcode icloud uidocument