【问题标题】:iCloud Documents not visibleiCloud 文档不可见
【发布时间】: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


【解决方案1】:

我发现了问题所在: iCloud 容器的 Info.plist 中的键与格式“iCloud.com.example.MyApp”有点不同。

【讨论】:

  • 告诉我们它有何不同。你什么意思?
【解决方案2】:

我按照link 的说明查看我的应用在 iCloudDrive 中创建的文件。我可以从设置>iCloud>设备存储中查看文件。希望对您有所帮助。

【讨论】:

    猜你喜欢
    • 2016-02-16
    • 2015-08-17
    • 1970-01-01
    • 1970-01-01
    • 2020-05-04
    • 1970-01-01
    • 1970-01-01
    • 2012-12-30
    • 1970-01-01
    相关资源
    最近更新 更多