CoreData 与 CloudKit:记录类型未显示在仪表板中

问题描述 投票:0回答:4

我正在通过 NSPersistentCloudKitContainer 将 CloudKit 支持添加到我的应用程序中。

在开发人员门户中,我向我的应用程序标识符添加了 iCloud 和推送通知功能,下载了新的配置文件并将其安装在 Xcode 上。在 iCloud 中,我检查了“CloudKit 支持”并为我的应用程序启用了一个容器。

在我的应用程序目标“签名和功能”中,我启用了远程通知和 CloudKit,并检查了容器。

现在我使用 NSPersistentCloudKitContainer 运行我的应用程序以获取所有核心数据内容。我执行创建新的托管对象的任务。这是在我使用 iCloud 登录的设备上。

在 CloudKit 仪表板中,我看到了应用程序的容器,但没有看到任何对象已进入云的证据。我在开发中,单击“记录类型”,我希望看到我的实体中的一些“CD_...”。仅显示用户记录类型。

我从头开始重新安装了应用程序,以查看之前创建的对象是否从云端同步,但没有,显然那里什么也没有。

有什么想法吗?

更新:在我的设备上,我使用我的个人 Apple ID 登录。我已使用同一 ID 注册了开发者计划。该应用程序未显示在使用 iCloud 的应用程序列表中。

ios core-data cloudkit
4个回答
2
投票

在 WWDC19 会议中,将 Core Data 与 CloudKit 结合使用,他们提到他们为使用 Core Data/CloudKit 集成的应用程序使用自定义区域。要查看数据,请从 CloudKit 仪表板中选择私有数据库,然后选择为您创建的自定义 CloudKit 区域。从那里,选择您的记录类型,然后选择查询记录。然后您应该会看到您的数据出现。


1
投票

不知何故,我在创建 NSPersistentStoreDescription 时错过了这一步:

description.cloudKitContainerOptions = NSPersistentCloudKitContainerOptions(containerIdentifier: "blah")

我还没有在仪表板中看到它,因为现在我收到一个关于数据库模型与 CloudKit 不兼容的错误!但这是另一个故事了。


0
投票

我找出了 CloudKit 仪表板中缺少架构的原因。您应该创建一条记录并保存它,这样您就可以触发同步(也许?)并再次检查 CloudKit 仪表板,您将看到新创建的架构。


0
投票

我必须更新一个旧的 Objective-C 应用程序,并努力了三天才能让 CloudKit 架构更新正常工作。遗憾的是,即使是 Apple 文档也没有彻底向您展示如何在 Objective-C 中实现。

我的问题是我使用了错误的代码来初始化 NSPersistentCloudKitContainerOptions。

这是我实际运行的 Objective-C 代码...

    NSPersistentCloudKitContainer* container = [NSPersistentCloudKitContainer persistentContainerWithName:"MyApp"  managedObjectModel:_managedObjectModel];

    NSURL *localStoreURL = [[[[NSFileManager defaultManager] URLsForDirectory:NSDocumentDirectory inDomains:NSUserDomainMask] lastObject] URLByAppendingPathComponent:@"MyApp.sqlite"];
    NSPersistentStoreDescription* localdesc = [NSPersistentStoreDescription persistentStoreDescriptionWithURL:localStoreURL];
    //the following line is the piece I couldn't find elsewhere on the Web
    localdesc.cloudKitContainerOptions = [[NSPersistentCloudKitContainerOptions alloc]  initWithContainerIdentifier:@"iCloud.com.myapp"];
    localdesc.cloudKitContainerOptions.databaseScope = CKDatabaseScopePrivate;

    container.persistentStoreDescriptions = @[localdesc];
    [container loadPersistentStoresWithCompletionHandler:
     ^(NSPersistentStoreDescription *storeDescription, NSError *error) {
      if (error != nil) {
        NSLog(@"Failed to load store: %@", error);
        abort();
      }
    }];

#if DEBUG
    NSError *err;
    // The following line will populate the CloudKit Schema RecordTypes ONLY if your device (or simulator) is logged into iCloud!!
    // Use NSPersistentCloudKitContainerSchemaInitializationOptionsPrintSchema if you
    // just want to print out what it will export
    [container initializeCloudKitSchemaWithOptions: NSPersistentCloudKitContainerSchemaInitializationOptionsNone error: &err];
    if (err != nil) {
      NSLog(@"Failed to create schema: %@", err);
    }
#endif

我发现这些链接很有帮助:

© www.soinside.com 2019 - 2024. All rights reserved.